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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With