我来自微软世界,所以请耐心等待。有人告诉我可以安装 node.js 并将其用作 Web 服务器而不是 IIS。这是一个非常小的商业应用程序。在 IIS 中,我可以创建虚拟目录并指向网页的位置,一切正常。根据我读到的很少的内容,我有几个问题;
- 是否可以将 Node js 作为 Windows 服务或任何其他形式运行,以便它永远运行?我确实找到了我认为可以使用的
forever
包。 - 在 IIS 中,我可以创建虚拟目录并设置端口,仅此而已,我自己就有了一个网站。
我没有看到任何可以使用一个目录的示例,其中我有一个用java脚本编写的网页,并将其指向作为网站运行。所有示例都有一些类似 server.js 的东西,它运行并路由调用。托管网站并使用 Node.js 作为快速 Web 服务器简单运行的其他方式是什么?
最佳答案
I was told I could install node.js and use that as a web server instead of IIS.
这是事实,但正如您已经发现的那样,您负责提供 IIS 已经为您做的事情(例如,在重新启动或崩溃时自动重新启动、通过创建虚拟文件夹托管多个站点等) .)
您确实可以在 Node.js 中解决所有这些问题,并且有几个库可以在每个领域提供帮助。这并不太难,但您需要做一些研究。
您还可以在 IIS 后面运行 Node.js。看看iisnode http://tomasz.janczuk.org/2011/08/hosting-nodejs-applications-in-iis-on.html
Is it possible to run node js as a windows service or any other form so that it runs for ever?
Forever 库负责在网站崩溃时重新启动网站...但我不知道您是否可以将其作为 Windows 服务运行。我没试过。
In IIS, I can create virtual directory set the port and thats it, I have myself a website.
我假设您正在谈论一个提供静态 HTML 文件的网站,对吗?如果是这种情况,则很容易在 Node.js 中提供支持,无论是编写自己的 Web 服务器还是使用 Express.js 提供静态文件。
I do not see any examples where I can use a directory where I have a web page, written in java script and point it to run as a web site. All the examples have some thing like server.js and that runs and routes the call.
这是一个在 Node.js 中提供纯 HTML 文件的极其简单的示例 https://gist.github.com/2573391不过,不要在生产中使用它。这只是一个示例,没有任何类型的错误处理或安全性。
what is the other way to host web sites and use node.js to simple run as a fast web server.
正如其他人所说,您应该查看 Express.js http://expressjs.com/它提供了您在构建传统网站时很可能需要的一些基础设施。
关于node.js - 如何用 Node.js 替换 IIS 来构建简单网站,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13818483/