Skip to content

Instantly share code, notes, and snippets.

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