33 lines
757 B
JavaScript
33 lines
757 B
JavaScript
// const http = require("http")
|
|
// const fs = require("fs")
|
|
|
|
// // 创建本地服务器来从其接收数据
|
|
// const server = http.createServer((req, res) => {
|
|
// console.log("url: ",req.url);
|
|
// res.writeHead(200, { 'Content-Type': 'text/htML' });
|
|
|
|
// if (req.url.includes("html")) {
|
|
// let data = fs.readFileSync(`.${req.url}`)
|
|
// res.end(data.toString())
|
|
// }
|
|
// });
|
|
|
|
// server.listen(8000);
|
|
|
|
const express = require('express')
|
|
const app = express()
|
|
const port = 3000
|
|
|
|
app.get('/', (req, res) => {
|
|
res.render('index', function (err, html) {
|
|
res.send(html)
|
|
})
|
|
})
|
|
|
|
app.get('/test', (req, res) => {
|
|
res.send('Hello World!')
|
|
})
|
|
|
|
app.listen(port, () => {
|
|
console.log(`Example app listening on port ${port}`)
|
|
}) |