- res.writeHead to set any response headers.
res.writeHead(200, { "Content-Type": "text/html" });
- res.write() to send the actual content for the response. the content should be either raw html or json data.
res.write("<h1>Welcome to vanilla node server</h1>");
or,
res.write(JSON.stringify(data));
- res.end() to end the response.
res.end();
res.writeHead(200, { "Content-Type": "text/html" });
res.write("<h1>Welcome to vanilla node server</h1>");
res.end();
res.writeHead(200, { "Content-Type": "application/json" });
res.write(JSON.stringify(data));
res.end();