[英]Getting Error res.setHeader not a Function
I am trying to create a nodejs server.我正在尝试创建一个 nodejs 服务器。 I used res.setHeader method to set content-type as text/html.
我使用res.setHeader方法将内容类型设置为 text/html。 But after starting the server getting error that res.setHeader is not a function;
但是在启动服务器后得到错误res.setHeader is not a function; Following is my code:
以下是我的代码:
const http=require('http'); const server=http.createServer((res,req)=>{ res.setHeader('Content-Type','text/html') res.write('<h1>Hello This is response from NodeJS>Server</h1>') res.end() }) server.listen(8000);
I have attached image that clearly shows that this is not a function我附上的图片清楚地表明这不是 function
res
is the second argument, not the first argument. res
是第二个参数,而不是第一个参数。
const server=http.createServer((req, res)=>{
...
Here is the doc: https://expressjs.com/en/guide/routing.html这是文档: https://expressjs.com/en/guide/routing.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.