简体   繁体   English

如何使用多个node.js文件

[英]How to use multiple node.js files

I am having trouble having my VS17 Node.js project use multiple node.js files to generate webpages. 我在让我的VS17 Node.js项目使用多个node.js文件生成网页时遇到麻烦。 The have the standard http.createServer, but only one will generate. 具有标准的http.createServer,但只会生成一个。 When I change the url to another Node file, it says it can't load that localhost. 当我将URL更改为另一个Node文件时,它说它无法加载该本地主机。

Can any of you help? 你们有什么可以帮忙的吗? Does it have anything to do with package.json? 它与package.json有关系吗?

If you're new to node, you should consider using a framework like expressjs. 如果您不熟悉Node,则应考虑使用expressjs之类的框架。 It will abstract away a lot of the hard stuff so you can focus more on just making a website, and not reinventing the wheel. 它将抽象出很多硬性内容,因此您可以将更多的精力放在仅创建网站上,而不用重新发明轮子。

https://expressjs.com/ https://expressjs.com/

There is a generator utility that will scaffold your project for you. 有一个生成器实用程序可以为您搭建项目。

https://expressjs.com/en/starter/generator.html https://expressjs.com/cn/starter/generator.html

Install the generator 安装发电机

npm install express-generator -g

Run the generator 运行发电机

express ./myapp/

Then you will have a fully functional server that you can run with npm start 然后,您将拥有一个可以通过npm start运行的功能齐全的服务器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM