Vue2:用node+express写一个轻量级的后端服务

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

5、访问

相关推荐
GDAL3 天前
express.urlencoded深入全面讲解教程
express·urlencoded
GDAL4 天前
express.urlencoded和fetch结合使用
express·form·fetch
GDAL4 天前
express.json 深入全面讲解教程
json·express
GDAL4 天前
Express 中 CORS 跨域问题解决教程
express·cors
GDAL4 天前
express.text和fetch配合使用深入全面教程
express·text
GDAL5 天前
Express POST 请求深入全面讲解教程
express
正经教主5 天前
【Trae+AI】和Trae学习搭建App_2.1:第3章·手搓后端基础框架Express
人工智能·后端·学习·express
你真的可爱呀9 天前
2.Express 核心语法与路由
中间件·node.js·express
骚团长9 天前
SQL server 配置管理器-SQL server 服务-远程过程调试失败 [0x800706be]-(Express LocalDB卸载掉)完美解决!
java·服务器·express
你真的可爱呀9 天前
1.基础环境搭建与核心认知
node.js·express