在node.js中侦听端口80时如何打开localhost?
我目前正在node.js中开始,我想在localhost中打开我的server.js文件。URL目录路径是什么,正如我注意到的,您不需要文件所在的文件夹名,就像在Apache中一样在node.js中侦听端口80时如何打开localhost?,node.js,localhost,Node.js,Localhost,我目前正在node.js中开始,我想在localhost中打开我的server.js文件。URL目录路径是什么,正如我注意到的,您不需要文件所在的文件夹名,就像在Apache中一样 但我不确定。否则,我的目录就是下面的桌面/node projects/exercise node mongo/server.jsnode.js不是专门为运行web应用程序而设计的,您需要在node.js中使用自己的代码创建web服务器 在Node.js上运行网站的流行框架是Express,只需打开存储在中的文件夹se
但我不确定。否则,我的目录就是下面的桌面/node projects/exercise node mongo/server.jsnode.js不是专门为运行web应用程序而设计的,您需要在node.js中使用自己的代码创建web服务器 在Node.js上运行网站的流行框架是Express,只需打开存储在中的文件夹
server.js
中的命令提示符,然后运行以下步骤即可安装该框架:
npm install express
安装expressserver.js
const express = require('express')
const app = express()
const port = 3000
app.get('/', (req, res) => res.send('Hello World!'))
app.listen(port, () => console.log(`Example app listening on port ${port}!`))
node server.js
来运行应用程序localhost:3000
,您将看到文本Hello World代码>显示
您应该查看express指南,了解更多有关其工作原理的信息。Node.js不是专门为运行web应用程序而设计的,您需要在Node.js中使用自己的代码创建web服务器 在Node.js上运行网站的流行框架是Express,只需打开存储在中的文件夹
server.js
中的命令提示符,然后运行以下步骤即可安装该框架:
npm install express
安装expressserver.js
const express = require('express')
const app = express()
const port = 3000
app.get('/', (req, res) => res.send('Hello World!'))
app.listen(port, () => console.log(`Example app listening on port ${port}!`))
node server.js
来运行应用程序localhost:3000
,您将看到文本Hello World代码>显示