Skip to content

Instantly share code, notes, and snippets.

@nodox
Forked from aparrish/simple-express.js
Last active April 3, 2019 20:11
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 nodox/a85120a3b380cef327f6fcf61cfc2fbd to your computer and use it in GitHub Desktop.
Save nodox/a85120a3b380cef327f6fcf61cfc2fbd to your computer and use it in GitHub Desktop.
Simplest possible Express application
// 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