Skip to content

Instantly share code, notes, and snippets.

@dalelane
Created June 15, 2014 21:02
Show Gist options
  • Save dalelane/494433bb2d1fa9d3d4c3 to your computer and use it in GitHub Desktop.
Save dalelane/494433bb2d1fa9d3d4c3 to your computer and use it in GitHub Desktop.
Node.js and Express to make a few REST API endpoints (based on sample in http://expressjs.com/4x/api.html )
var express = require('express');
var app = express();
console.log("Registering endpoint: /");
app.get('/', function(req, res){
res.send('hello ROOT world');
});
console.log("Registering endpoint: /stubbed");
app.get('/stubbed', function(req, res){
res.send('hello STUBBED');
});
console.log("Registering endpoint: /testing");
app.get('/testing', function(req, res){
res.send('this is a test endpoint');
});
console.log("Registering endpoint: /jsonendpoint");
app.get('/jsonendpoint', function(req, res){
res.json({
"mykey" : "myvalue",
"testy" : "something",
"exnum" : 123
});
});
app.listen(3000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment