Here's an example of how to create a basic HTTP server with a HEAD route in TypeScript:
index.ts392 chars21 lines
In the code above, we're using the built-in http
module to create an HTTP server that listens on port 3000. We're then checking the incoming request method - if it's a HEAD
request, we're sending back a plain text response with a 200
status code and a Content-Length
of 0
. If it's not a HEAD
request, we're sending back a 404
status code.
Note that this is just a basic example - you'd want to add more routes and functionality to the server depending on your specific use case. You could also use a web framework like Express or NestJS to handle routing and middleware.
gistlibby LogSnag