Skip to content

Instantly share code, notes, and snippets.

@cpoDesign
Created August 21, 2014 08:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cpoDesign/e5f2e3928f0d40f249e4 to your computer and use it in GitHub Desktop.
Save cpoDesign/e5f2e3928f0d40f249e4 to your computer and use it in GitHub Desktop.
Register jade view engine with server
{
"name": "application-name",
"version": "0.0.1",
"description": "test server",
"author": {
"name": "cpo",
"email": "pavel.svarc@cpodesign.com"
},
"dependencies": {
"express": "^4.8.5",
"underscore": "^1.6.0",
"jade": "^1.5.0"
}
}
var http = require('http');
var express = require('express');
var _ = require('underscore');
var app = express();
// Setup view engine
app.set('view engine','jade');
// sending plain html
app.get('/', function(req, res){
res.send('<html><body><h1>Express</h1></body></html>');
});
// will serialize data as json automatically
app.get('/api/users', function(req, res){
res.set('Content-Type','application/json');
// if type of content is not specified the browser will attempt to infer it from data
res.send({name:'Joe', isValid: true, group: 'Admin'});
});
var server = http.createServer(app);
server.listen(3000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment