const express = require('express'); // 加载express
const app = express(); // 设置app为别名
const port = 3000; // 端口设置为3000
// get方法,当浏览器访问时调用,一旦调用在console输出请求方法
// 响应send方法,客户端浏览器显示string内容
app.get("/", (req,res) => {
console.log(`New request made: ${req.method}`);
res.send("Hello from the server!");
});
// 监听localhost:端口
app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});
展开/折叠结果
Server is running on port 3000
New request made: GET
发表评论