Here's an example of how you can return an HTML response from an HTTP server using TypeScript:
index.ts317 chars12 lines
In this example, we create an HTTP server using the http
module that comes with Node.js. Inside the callback function that handles incoming requests, we set the response header to indicate that we are returning HTML content, and we write the HTML content to the response body.
Once we have finished writing the response, we call response.end()
to signal to the server that we have finished sending the response back to the client.
We then call the listen()
method on our server object to start listening for incoming requests on port 3000.
gistlibby LogSnag