当前位置:网站首页>node+express搭建服务器环境
node+express搭建服务器环境
2022-07-17 10:41:00 【程序三两行】
一、概述
express是一个基于 Node.js 平台,快速、开放、极简的 Web 开发框架,
网址
Express - 基于 Node.js 平台的 web 应用开发框架 - Express 中文文档 | Express 中文网
http://expressjs.com/
二、如何搭建
1、创建项目
创建一个文件夹进入cmd执行npm init
E:\idea_workspace\demo>npm init
定义一个package name 然后一直回车即可
package name: (demo) demoExpress
引入express
E:\idea_workspace\demo>npm i express
2、编写server.js
上面的demo文件下创建server.js文件
/*引入express*/
const express = require("express")
/*创建一个app实列调用对象*/
const app = express()
/*配置路由*/
app.get('/getUser',(req,res)=>{
res.send({
name:'tom',
age:18
})
})
/*监听对象并收到错误回调*/
app.listen(5005,(err)=>{
if(!err) console.log("服务器启动成功!")
})3、启动测试
E:\idea_workspace\demo>node server 服务器启动成功!
4、发布项目
见打包好的文件放在项目下新建的static(自定义文件名)文件夹

配置
/*引入express*/
const express = require("express")
/*创建一个app实列调用对象*/
const app = express()
/*配置项目路径*/
app.use(express.static(__dirname+'/static'))
/*还可以自定义配置路由*/
app.get('/getUser',(req,res)=>{
res.send({
name:'tom',
age:18
})
})
/*监听对象并收到错误回调*/
app.listen(5005,(err)=>{
if(!err) console.log("服务器启动成功!")
})启动访问
node server
5、处理vue项目的支持history模式
安装中间件
npm i connect-history-api-fallback
配置
const express = require("express")
/*引入history处理中间件*/
var history = require('connect-history-api-fallback');
const app = express()
/*使用*/
app.use(history())
app.use(express.static(__dirname+'/static'))
app.get('/getUser',(req,res)=>{
res.send({
name:'tom',
age:18
})
})
app.listen(5005,(err)=>{
if(!err) console.log("服务器启动成功!")
})边栏推荐
- Uniapp warehouse management system source code
- [C language] storage of shaping data
- 【洛谷】P2357 守墓人
- 第1周学习:深度学习入门和pytorch基础
- 【愚公系列】2022年7月 Go教学课程 012-强制类型转换
- Un7.16: how to deploy projects on code cloud and invite team members?
- [Network Research Institute] the threat of machine learning system is time to take it seriously
- DEDECMS织梦文章列表标题重复显示解决方案
- idea卡顿且报错:UI was frozen for xxxxx ms问题解决
- Fundamentals of C language -- 2-1 pointer and wild pointer
猜你喜欢

【C语言】void类型和void*指针类型

Yanrong technology was selected as Beijing's "specialized and innovative" in 2022 to lead hybrid cloud file storage

Develop the first Flink app

Es conceptual model and basic faults

Part I - Fundamentals of C language_ 5. Arrays and strings

Detailed explanation of C51 common data types
![[C language] void type and void* pointer type](/img/4c/3643d850bfcb57db93496ec9bba06e.png)
[C language] void type and void* pointer type

Target detection model size calculation, model complexity (parameter conversion formula)
![[performance optimization methodology series] VI. summary](/img/46/81261e4ed5c1efe48acb979ac39f7b.jpg)
[performance optimization methodology series] VI. summary

SAP Fiori 的附件处理(Attachment handling)
随机推荐
【愚公系列】2022年7月 Go教学课程 012-强制类型转换
C语言基础篇 —— 2-2 const关键字与指针
Fundamentals of C language -- 2-2 const keywords and pointers
MySQL user management
C51 常见数据类型详解
2022.7.16-----leetcode. Sword finger offer 041
【摸鱼神器】UI库秒变低代码工具——表单篇(二)子控件
实用工具系列 - Xshell安装下载与使用
how to use culasLt
Chapter 10 stack of STL
idea卡顿且报错:UI was frozen for xxxxx ms问题解决
Flink small knowledge -- configuration of task scheduling slots slotsharinggroup
OLED displays how to understand the character sizes of 12*6, 16*8, 24*12, etc
Memory LDA LDA in Blas level-3 sgemm cublesgemmex cubulassgemm
第4章-一阶多智体系统一致性 -> 连续时间含时延系统一致性
【性能优化方法论系列】六、总结
第十三章 STL 之 set/ multiset
R语言data.table导入数据实战:data.table使用dcast.data.table函数实现透视表(pivot table)
[Luogu] p2357 tomb keeper
The study found that DNA nano device injection can be safely used for medical purposes