Created
August 21, 2014 08:21
-
-
Save cpoDesign/e5f2e3928f0d40f249e4 to your computer and use it in GitHub Desktop.
Register jade view engine with server
This file contains 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": "application-name", | |
"version": "0.0.1", | |
"description": "test server", | |
"author": { | |
"name": "cpo", | |
"email": "[email protected]" | |
}, | |
"dependencies": { | |
"express": "^4.8.5", | |
"underscore": "^1.6.0", | |
"jade": "^1.5.0" | |
} | |
} |
This file contains 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
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