Nikhil Taralekar
Nikhil Taralekar

Reputation: 51

Running Node.js server on windows

How can I host node.js application on windows server?

Upvotes: 5

Views: 15475

Answers (2)

Brando Zhang
Brando Zhang

Reputation: 27997

I suggest you use iisnode to achieve your requirement.

You should firslty install the IIS URL Rewrite extension, node.js, iisnode.

After you installed above things, you could find you IIS Modules contains the IISnode feature, then you could run your node.js application on IIS as other web application.

More details about how to host node.js application, you could refer to below article.

https://www.hanselman.com/blog/InstallingAndRunningNodejsApplicationsWithinIISOnWindowsAreYouMad.aspx

https://www.simplymigrate.com/2017/04/11/internet-information-server-iis-node-js-in-producton-iisnode/

Upvotes: 3

Amir
Amir

Reputation: 1905

1) install nodejs (Download from here)

2) write your server program (it should contain a proper node.js listener code)

3) run your code; open a Powershell or CMD and type the following command:

node my_server.js

you can also refer to these links:

Install Node.js and NPM on Windows

PM2 | process manager for Node.js

P.S:

Here is a very very simple node.js server code (from node.js docs here):

const http = require('http');

const hostname = '127.0.0.1';
const port = 3000;

const server = http.createServer((req, res) => {
    res.statusCode = 200;
    res.setHeader('Content-Type', 'text/plain');
    res.end('Hello, World!\n');
});

server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});

Hope it helps!

Upvotes: 2

Related Questions