赞
踩
新建一个空文件夹
初始化项目 yarn init -y
=> package.json
配置 .gitignore
文件 node_modules/
安装Express插件 yarn add express
创建 app.js
用于搭建后端服务器
```js ├── README.en.md ├── README.md ├── app.js ├── package.json └── yarn.lock const express = require('express') const app = express() // 非常简单的 API 端点 app.get('/',(req,res) => { res.send('Hello World') }) // 启动服务器监听来自指定端口 8081 app.listen(8081, () => { console.log('Server is running on http://localhost:8081') }) ```
启动服务器 nodemon app.js
在浏览器中访问路由 http://localhost:8081
页面通过res.send()
展示 'Hello World'
作为页面内容
终端会打印出 Server is running on http://localhost:8081
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。