Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I am working on nodejs app in typescript in which i have wrote a file server.js as fallow :

import express = require('express');
import mongoose = require('mongoose');
let app=express();
app.set('port', process.env.PORT || 3000); // Set port to 3000 or the provided PORT variable
 * Start app 
app.listen(app.get('port'), function() {
  console.log(`App listening on port ${app.get('port')}!`);

i have use the gulp to traspile it which generate js file as

define(["require", "exports", 'express'], function (require, exports, express) {
    var app = express();
    app.set('port', process.env.PORT || 3000); // Set port to 3000 or the provided PORT variable
     * Start app
    app.listen(app.get('port'), function () {
        console.log("App listening on port " + app.get('port') + "!");
//# sourceMappingURL=../map/server.js.map

but when i run this file am getting error define is not define.

Please correct me if i am doing any mistake.

If you are writing an application that will run purely in Node.js, you should be using "commonjs" modules, not AMD modules, when you compile your TypeScript files.

If you are writing an application that will run both in Node.js and in the browser, you should be using "umd" modules, not AMD modules, when you compile your TypeScript files.

So, you need to change your the configuration object you pass to the Gulp TypeScript compiler to use { module: "commonjs" } or { module: "umd" }.

I guess you need an amd-loader here, once installed you can then require("amd-loader"); in your project.

npm install amd-loader
require("amd-loader");

Below is the link:

https://github.com/ajaxorg/node-amd-loader

I have a module that is defined but is not yet loaded (as indicated by its loaded property. How do I wait for it to load? – phreed Dec 7, 2016 at 18:45

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.