Created
August 21, 2014 08:18
-
-
Save cpoDesign/e240d814362834e9dedc to your computer and use it in GitHub Desktop.
Example of using node express package to create basic server behavior
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(); | |
// 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