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、访问

相关推荐
掉头发类型的选手11 小时前
Node.js: express 使用 Open SSL
express
不写八个5 天前
Express教程【006】:使用Express写接口
express
課代表5 天前
Adobe LiveCycle ES、LiveCycle DS 与 BlazeDS 关系解析与比较
数据库·adobe·pdf·express·livecycle·lcds·soa平台
不写八个8 天前
Express教程【002】:Express监听GET和POST请求
前端·javascript·express
不写八个8 天前
Express教程【003】:Express获取查询参数
开发语言·express
爱编程的小学究12 天前
【node】Express创建服务器
运维·服务器·express
码农捻旧13 天前
基于GitHub Actions+SSH+PM2的Node.js自动化部署全流程指南
node.js·自动化·ssh·github·express
漫谈网络14 天前
基于TypeScript的全栈待办事项应用Demo
前端·javascript·typescript·node.js·express
xx240616 天前
什么是Express
express
码农捻旧17 天前
Node.js Express 项目现代化打包部署全指南
javascript·node.js·github·express