Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to run node.js app from cmd with some predefined port in Windows

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);
like image 361
silent_coder Avatar asked Sep 24 '13 10:09

silent_coder


People also ask

How do I run a node js script in Windows?

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.


1 Answers

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
like image 85
Ph0en1x Avatar answered Oct 23 '22 04:10

Ph0en1x