1. Erstellen Sie ein neues leeres Projekt
2. Initialisieren Sie npm
npm init -y
3. Express installieren
npm install express -s
4.lanbowan_server/Index.js:
Erstellen Sie eine neue index.js-Datei im Stammverzeichnis
const express=require('express')
const router=require('./router/router.js')
// 创建服务器
const app=express();
app.use('/',router)
app.listen('7788',()=>{
console.log('服务端启动成功啦。。。。。');
console.log('http://localhost:7788');
})
lanbowan_serve/router/router.js:
const express=require('express')
// 路由
const router=express.Router();
router.get('/test',(req,res)=>{
res.send({
data:'测试成功'
})
})
module.exports=router;
5. Testen Sie, ob der Server erfolgreich ist
Auffüllen:
Starten Sie Dienste automatisch mit Nodemon neu
Globale Installation
npm install -g nodemon
Installation der Entwicklungsumgebung
npm install --save-dev nodemon
Geben Sie nodemon bei der Verwendung direkt ein