const express = require('express');
const path = require('path');
const app = express()
const port = 5000
const log = console.log
app.use(express.static('public'))
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, "./index.html"))
// res.render('')
})
app.get('/jq', (req, res) => {
log(path.join(__dirname, "../../html/js/jquery-3.7.0.min.js"))
res.sendFile(path.join(__dirname, "../../html/js/jquery-3.7.0.min.js"))
})
app.get('/xxx', (req, res) => {
res.send({ name: 'fdasfs' }).status(200)
})
app.listen(port, () => {
log(`http://127.0.0.1:${port}`)
})
创建index.js 文件,把代码写入
npm init
npm i express
node index.js