Skip to content

Instantly share code, notes, and snippets.

@tmlbl
Last active August 29, 2015 13:56
Show Gist options
  • Save tmlbl/8967040 to your computer and use it in GitHub Desktop.
Save tmlbl/8967040 to your computer and use it in GitHub Desktop.
A 'Hello World' server for Node.js, Express, Jade and Heroku
/* Filepath: ./app/views/index.jade */
doctype
html
head
title My Page
body
h1 Hello, World!
/* Use Express and Jade, 'app' represents the Express server */
var express = require('express'),
jade = require('jade'),
app = express();
/* Global settings for express */
app.configure(function () {
app.set('view engine', 'jade'); // Views are in Jade
app.set('views', __dirname + '/app/views'); // View folder is ./app/views/
app.use(express.bodyParser()); // Makes http bodies readable
app.use('/public', express.static(__dirname + '/public')); // Static dir is ./public
});
/* A 'GET' to the root will render the index view */
app.get('/', function (req, res) {
res.render('index');
});
/* Server will start on 5000 locally, or on environment port on Heroku */
var port = process.env.PORT || 5000;
app.listen(port, function () {
console.log('Listening on ' + port);
});
{
"name": "Express Example",
"version": "0.0.1",
"description": "Express example",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": ""
},
"author": "Tim Lebel",
"license": "BSD-2-Clause",
"dependencies": {
"express": "~3.4.8",
"jade": "~1.1.5"
}
}
web: node index.js
.
├── app
│   └── views
├── index.js
├── node_modules
│   ├── express
│   └── jade
├── package.json
└── Procfile
@tmlbl
Copy link
Author

tmlbl commented Feb 12, 2014

to run: node index.js
navigate browser to: localhost:5000

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment