To create a HTTP server in Typescript, we can use the Express.js framework along with Node.js. Follow the steps below to create a server on a specific port:
index.ts86 chars3 lines
server.ts
and add the following code to it:index.ts290 chars15 lines
Compile the TypeScript file into JavaScript using the command tsc server.ts
. This will generate a new file called server.js
.
Run the server by executing the command node server.js
This will start the server and it will be accessible at http://localhost:3000/.
gistlibby LogSnag