基于node 安装express后端脚手架

1.首先创建文件件

2.在文件夹内打开终端 npm init

3.安装express:

复制代码
npm install -g express-generator

注意的地方:这个时候安装特别慢,最后导致不成功

解决方法:npm config set registry http://registry.npm.taobao.org/

4.依次执行

复制代码
npm install -g express-generator

 npm i express

5.创建接口

复制代码
// 引入express
const express = require('express')
// 创建实例
const app = express()
// 创建监听端口
const port = 3000
//  定义接口
app.get('/api/getData',(req,res) =>{
    // 返回的结果
    res.send({
        code:10000,
        data:{
            msg:'hellow '
        }
    })
})
// 监听当前的端口
app.listen(port,() =>{
    console.log(`server start! port:${port}`);
})

5.运行node

6.测试刚才接口有没有创建成功

复制代码
http://localhost:port(端口号)/app.get(接口路径)
相关推荐
Dumbness1 天前
一个手机号验证码登录接口的五个坑:无限发码、无限试码,传个数字就让 Express 进程退出
node.js·express
星光开发者9 天前
基于springboot智慧草场牛羊管理系统-计算机毕设【课程设计】50360
vue.js·spring boot·后端·mysql·php·课程设计·express
vx_Biye_Design13 天前
django房屋租赁推荐系统78455-计算机课程设计、毕业设计
vue.js·spring boot·后端·python·django·课程设计·express
vx_Biye_Design16 天前
PHP中医养生馆预约系统60841-计算机课程设计、毕业设计
vue.js·spring boot·后端·mysql·php·课程设计·express
夏幻灵17 天前
Express 静态资源托管详解:从本地 HTML 到 express.static()
前端·html·express
毕业设计70320 天前
(免费领源码)基于node的学生公寓管理系统06412- java、PHP、python、C#、小程序、大数据、单片机、网络工程等)
vue.js·mysql·node.js·maven·mybatis·express·b/s
Wx-bishekaifayuan21 天前
springboot桂味美食分享系统40540-计算机课程设计、毕业设计
spring boot·后端·python·django·课程设计·express·旅游
Wx-bishekaifayuan23 天前
express皖美特色农产品网售系统53118-计算机课程设计、毕业设计
人工智能·spring boot·后端·python·课程设计·express·旅游
Wx-bishekaifayuan23 天前
springboot汉中旅游服务平台41442-计算机课程设计、毕业设计
spring boot·后端·python·django·课程设计·express·旅游
Wx-bishekaifayuan23 天前
springboot公考微信小程序35511-计算机课程设计、毕业设计
spring boot·后端·python·django·课程设计·express·旅游