Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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