Is it some command exist to run my node.js code with directly specified port?
something like node server.js port=7777
?
my server.js code looks like this
http.createServer(function (req, res) {
if (mount(req, res)) return;
}).listen(process.env.PORT || 80);
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