how to run node.js app from cmd with some predefined port in Windows
On ubuntu I just do
PORT=7777 node .
in commandline, no set or export needed.
Depending on what server.js
contains you should be able to do so.
At a minimum you should read port
(you could use https://github.com/substack/node-optimist)
var argv = require('optimist').argv;
console.log(argv.port);
// use it like this
$ node server.js -port 7777
and then listen to it on your server (this depends on what lib you're using).
Run the server like this
export PORT=7777; node server.js
A simple adding to Alberto's answer. On Windows machine you haven't export
command in cmd
, use set
instead.
Then the whole script will be looks like this:
set PORT=7777
node server.js
Note that the syntax in PowerShell is slightly different:
$env:PORT=7777
node server.js