簡體   English   中英

在Windows上運行Node.js服務器

[英]Running Node.js server on windows

如何在Windows Server上托管node.js應用程序?

我建議您使用iisnode來滿足您的要求。

您應該先安裝IIS URL Rewrite擴展程序 node.js iisnode

安裝完上述內容后,您會發現IIS模塊包含IISnode功能,然后您可以像其他Web應用程序一樣在IIS上運行node.js應用程序。

有關如何托管node.js應用程序的更多詳細信息,您可以參考以下文章。

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

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

1)安裝nodejs( 從這里下載

2)編寫服務器程序(它應包含正確的node.js偵聽器代碼)

3)運行您的代碼; 打開Powershell或CMD並鍵入以下命令:

node my_server.js

您還可以參考以下鏈接:

在Windows上安裝Node.js和NPM

PM2 | Node.js的流程管理器

PS:

這是一個非常非常簡單的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}/`);
});

希望能幫助到你!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM