express的监听和get

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

评论

发表评论

了解 数据控|突破是我们的每一步 的更多信息

立即订阅以继续阅读并访问完整档案。

继续阅读