-
-
Save nodox/a85120a3b380cef327f6fcf61cfc2fbd to your computer and use it in GitHub Desktop.
Simplest possible Express application
This file contains hidden or 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
// simplest possible express app | |
var http = require('http'); | |
var express = require('express'); | |
var app = express(); | |
// local database. When you restart the express server, the values will reset to original | |
let db = [ | |
{ | |
name: "Mike", | |
age: 23, | |
}, | |
{ | |
name: "Steven", | |
age: 26, | |
} | |
] | |
app.get("/person", function(req, res) { | |
// grab query parameters from request | |
const dbIndex = req.query.index; | |
// find that person in the database variable able | |
let person = db[dbIndex]; | |
// return the person we are looking for | |
return res.json(person); | |
}); | |
http.createServer(app).listen(4000, function() { | |
console.log("Express server listening on port 4000"); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment