Skip to content

Instantly share code, notes, and snippets.

@beaucarnes
Last active June 20, 2019 17:44
Show Gist options
  • Save beaucarnes/6cca9d24744c8cbcdabf84d212c83515 to your computer and use it in GitHub Desktop.
Save beaucarnes/6cca9d24744c8cbcdabf84d212c83515 to your computer and use it in GitHub Desktop.
const express = require('express');
const app = express();
const port = 3000;
let list = [];
app.get('/', (req, res) => {
res.json(list);
});
app.post('/add/:item', (req, res) => {
list.push(req.params.item);
res.json("Added " + req.params.item);
});
app.get('/:index', (req, res) => {
res.json(list[req.params.index])
});
app.delete('/:index', (req, res) => {
const item = list.splice(req.params.index, 1);
res.json("Deleted " + item);
});
app.post('/:index/:item', (req, res) => {
list[req.params.index] = req.params.item;
res.json("Updated " + req.params.item);
});
app.listen(port, () => console.log("Review server listening on port " + port));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment