Last active
August 29, 2015 13:56
-
-
Save tmlbl/8967040 to your computer and use it in GitHub Desktop.
A 'Hello World' server for Node.js, Express, Jade and Heroku
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Filepath: ./app/views/index.jade */ | |
doctype | |
html | |
head | |
title My Page | |
body | |
h1 Hello, World! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
web: node index.js |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
. | |
├── app | |
│ └── views | |
├── index.js | |
├── node_modules | |
│ ├── express | |
│ └── jade | |
├── package.json | |
└── Procfile |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
to run:
node index.js
navigate browser to:
localhost:5000