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.

lorless
  • 4,126
  • 8
  • 30
  • 41
  • Perhaps you should explain what the mac command does. – Magoo Dec 01 '15 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. – lorless Dec 01 '15 at 14:11
  • possible with [delayed Expansion](http://stackoverflow.com/a/30284028/2152082). What keeps you from using two lines? – Stephan Dec 01 '15 at 14:31

2 Answers2

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%
  • 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] – lorless Dec 01 '15 at 14:19
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.

Magoo
  • 77,302
  • 8
  • 62
  • 84