0

A bit of background, on mac you can do something like this

PORT=3002 NODE_ENV=dev node server.js 

But can you do the same on windows? I have tried

set PORT=3002 && echo %PORT% 

but the variable does not update until the echo is called again.

The reason I need this is that i am currently using npm start to run a script on a mac that looks like the first line of code. This does not work in windows since you cannot set env variables like that.

3
  • Perhaps you should explain what the mac command does. Commented Dec 1, 2015 at 14:07
  • It sets variables to use with the node server.js part of the command but only for this process, it does not affect system wide variables. Commented Dec 1, 2015 at 14:11
  • possible with delayed Expansion. What keeps you from using two lines? Commented Dec 1, 2015 at 14:31

2 Answers 2

4

In most contexts, surround the variable name with %'s and the variable's value will be used e.g. To display the value of the _department variable with the ECHO command:

ECHO %_department% 
Sign up to request clarification or add additional context in comments.

1 Comment

Right but I need two commands inline, one to set the variable, one to run a server with that new variable. Windows doesnt seem to update that variable until a new command is called. Ie i cant set and echo a variable in the same line]
0
@echo off setlocal enabledelayedexpansion set something=whatever&echo something=!something! 

But you seem to have no reason for wanting this on a single line.

1 Comment

Seeming to have no reason and having no reason are different things. Edited question anyway.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.