0

I create simple class (mymodule.ts):

export module MyModule {

export class MyClass  {
    Name: string;
    greet() {
        return "Hello world!";
    }       
  }
}

So, i have server.ts class (nodejs):

import http = require('http');
import my = require("mymodule");
var test=new my.MyModule.MyClass();
test.greet();
port = process.env.port || 1337
http.createServer(function (req, res) {
    res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Hello World\n');
}).listen(port);

But, i have error: Error TS2307 Cannot find module 'mymodule'.

I am new into node and typescript (C# background), so can you help me: how to include my own class into another class at nodejs?

Thank you!

1 Answer 1

1

You should remove the export module part and leave just:

export class MyClass  {
    Name: string;
    greet() {
        return "Hello world!";
    }       
  }

File is already a module in typescript.

And then:

var test=new my.MyClass();

Hope this helps.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.