Here is an example of how to make an HTTP HEAD request in TypeScript using the Node.js request library:
index.ts240 chars12 linesThis code imports the request library and uses the head function to make an HTTP HEAD request to the specified URL. The head function takes a callback function that is called once the request is complete. If an error occurs, the error is logged to the console. Otherwise, the status code and headers of the response are logged to the console.
Alternatively, you can use Promises to handle the response asynchronously:
index.ts254 chars12 linesIn this example, the request-promise library is used instead of request. The head function returns a Promise that is fulfilled with the response object when the request completes. If an error occurs, the Promise is rejected with the error object. The then method is used to handle the response, and the catch method is used to handle errors.
gistlibby LogSnag