[英]Running Node.js server on windows
如何在Windows Server上托管node.js应用程序?
I suggest you use iisnode to achieve your requirement. 我建议您使用iisnode来满足您的要求。
You should firslty install the IIS URL Rewrite extension , node.js , iisnode . 您应该先安装IIS URL Rewrite扩展程序 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. 安装完上述内容后,您会发现IIS模块包含IISnode功能,然后您可以像其他Web应用程序一样在IIS上运行node.js应用程序。
More details about how to host node.js application, you could refer to below article. 有关如何托管node.js应用程序的更多详细信息,您可以参考以下文章。
https://www.hanselman.com/blog/InstallingAndRunningNodejsApplicationsWithinIISOnWindowsAreYouMad.aspx https://www.hanselman.com/blog/InstallingAndRunningNodejsApplicationsWithinIISOnWindowsAreYouMad.aspx
https://www.simplymigrate.com/2017/04/11/internet-information-server-iis-node-js-in-producton-iisnode/ https://www.simplymigrate.com/2017/04/11/internet-information-server-iis-node-js-in-producton-iisnode/
1) install nodejs ( Download from here ) 1)安装nodejs( 从这里下载 )
2) write your server program (it should contain a proper node.js listener code) 2)编写服务器程序(它应包含正确的node.js侦听器代码)
3) run your code; 3)运行您的代码; open a Powershell or CMD and type the following command:
打开Powershell或CMD并键入以下命令:
node my_server.js
you can also refer to these links: 您还可以参考以下链接:
Install Node.js and NPM on Windows 在Windows上安装Node.js和NPM
PM2 | PM2 | process manager for Node.js
Node.js的流程管理器
PS: PS:
Here is a very very simple node.js server code (from node.js docs here ): 这是一个非常非常简单的node.js服务器代码(node.js的从文档这里 ):
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! 希望能帮助到你!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.