How do I use http in a typescript server

import http from 'http'

it doesnt find the http module or any node modules

As far as I know, using es modules in node requires .mjs extension.
Take a look at the node docs here:

trying to use with typescript which uses .ts

Try this:

import http = require('http');


import * as http from 'http'

require doesnt work in TS and it cant find 'http' module with import

I haven’t used Typescript with node myself, so I can’t test it.

I took the examples from here:

I see that the Microsoft Typescript starter repo is using normal imports? There might be some additional config that you’re missing perhaps. Check it out:

Seems like you may need to add "module": "commonjs", into your tsconfig if you’re missing it


import * as http from "http"; + the config is what’s necessary 99% of the time I’ve had issues

1 Like

doesnt work

npm i @types/node

this fixed it