[英]Order of data and end event of http.createServer
const server = http.createServer(async (request, response) => {
if (request.method === "POST") {
var data = "";
request
.on("data", async (chunk) => {
console.log("1");
data += chunk;
console.log("2");
await connection.query({sql query});
console.log("3");
})
.on("end", async () => {
console.log("4");
});
}
}
result below结果如下
1 4 2 3
1 4 2 3
Do you know how to process synchronously and make result order 1 2 3 4?你知道如何同步处理并使结果顺序为 1 2 3 4 吗?
If you want to add it synchronously, why add async keyword.如果要同步添加,为什么要添加 async 关键字。 And besides, I preferably would go with the modern day servers and use the express package for this.
此外,我最好将 go 与现代服务器一起使用,并为此使用快递 package。 Use this link: https://expressjs.com/en/starter/hello-world.html
使用此链接: https://expressjs.com/en/starter/hello-world.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.