Our First NodeJS / ExpressJS app

Posted in Articles

Tweet This Share on Facebook Bookmark on Delicious Digg this Submit to Reddit

This the code for our first NodeJS and ExpressJS app …

sample app.js code

You can put this code in either app.js or index.js.   But of course your package.json file should reference the correct filename for entry point. This code was explained in the context of a  previous tutorial here.

We will be using our first node app code as a basis for subsequent tutorials…

var express = require("express");
var app = express();
app.get('/', function(req, res) {
 res.send('First node app');
});
var port = Number(process.env.PORT || 3000);
app.listen(port, function() {
 console.log("Listening on " + port + "...");
});