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);
You can Run your JavaScript File from your Terminal only if you have installed NodeJs runtime. If you have Installed it then Simply open the terminal and type “node FileName. js”. If you don't have NodeJs runtime environment then go to NodeJs Runtime Environment Download and Download it.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With