Andry Andry - 9 months ago 123
TypeScript Question

How to use Node `http` module in TypeScript

I need to write a server in TypeScript and Node.

  1. I downloaded Node from DefinitelyTyped repository

  2. I created my typescript file

  3. Imported the definition

  4. Tries to use it

The result is:

/// <reference path="definitions/commonjs.d.ts" />
/// <reference path="definitions/node.d.ts" />

var http = require("http");

namespace MyProj {
export class Server {
public run() {
var server = http.createServer(); // TypeScript does not recognize 'http'

But I cannot understand how I can reference the
module. Where can I find the types? In the definition file i am having hard time recognizing this information.


It's because of you are using require. use import instead it will recognize and also will give you nice intellisense :-)

import * as http from "http"