1、桌面创建demo文件夹
进入demo,执行如下命令
bash
npm init
输入名称:
bash
test_server
然后一路回车
2、安装express框架
bash
npm i express
3、新建server.js
在demo文件夹中,新建server.js
javascript
const express = require('express')
const app = express()
app.get('/students',(request,response)=>{
const students = [
{id:'001',name:'tom',age:18},
{id:'002',name:'jerry',age:19},
{id:'003',name:'tony',age:120},
]
response.send(students)
})
app.listen(5000,(err)=>{
if(!err) console.log('服务器1启动成功了,请求学生信息地址为:http://localhost:5000/students');
})
4、启动
bash
node server