Here's an example code snippet using Node.js' built-in http
module to create a web server and send a response with HTML content:
index.tsx330 chars13 lines
In this example, we create a server instance using http.createServer()
and provide it with a request listener function that takes two arguments: the incoming HTTP request object and the response object that we'll use to send our HTML content.
We first set the content type header to 'text/html'
and the response status code to 200
(OK). Then we create the actual HTML content as a string and send it to the client in the res.end()
method.
If you run this code and navigate to http://localhost:3000
in your browser, you should see the "Hello World!" message displayed as a headline in your browser.
gistlibby LogSnag