壮壮灬

 

创建Node服务

1、创建空文件夹 01_Server

// 创建 package.json
npm init 

2、安装 node express 框架

npm i express 

3、创建 app.js

4、创建路由

/*
 * @Description: node
 * @Author: PengShuai
 * @Date: 2022-02-17 16:56:31
 * @LastEditors: PengShuai
 * @LastEditTime: 2022-02-18 15:10:39
 */
// 引用
var express = require('express')
var app = new express()
var usersInfo = [
  {
    name: 'pengshuai',
    QQ: '444655655',
  },
]
// post请求
app.post('/test', (req, res) => {
  res.send(usersInfo)
})
// 设置端口号
var port = process.env.PORT || 9898
app.listen(port)
// 输出
console.log('http://localhost:' + port + '/test')

5、启动 node app.js

//输出结果
http://localhost:9898/test

6、请求测试

posted on 2022-04-02 17:06  壮壮灬  阅读(34)  评论(0编辑  收藏  举报

导航