语法
2024年10月14日
一、Methods
1.1 express
const express = require("express");
const app = express();
app.get("/", (req, res) => {
res.send("Hello, Express with HTTP!");
});
app.listen(8000, () => {
console.log("Express HTTP Server is running on port 8000");
});
1.2 express http.createServer
将 Express
应用程序作为回调传递给 http.createServer()
,Express
会处理请求并生成响应。
const http = require("http");
const express = require("express");
const app = express();
const server = http.createServer(app);
app.get("/", (req, res) => {
res.send("Hello, Express with HTTP!");
});
server.listen(8000, () => {
console.log("Express HTTP Server is running on port 8000");
});