Skip to content

Instantly share code, notes, and snippets.

@nkreiger
Last active June 4, 2020 03:02
Show Gist options
  • Save nkreiger/56b249dc2d6f0d8d1a1a574d99f45e99 to your computer and use it in GitHub Desktop.
Save nkreiger/56b249dc2d6f0d8d1a1a574d99f45e99 to your computer and use it in GitHub Desktop.
const app = require('express')();
const bodyParser = require('body-parser');
// parse to json
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
// store integration
const { get, set } = require('./store');
// parse to json
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
// get from redis
app.get('/:key', async (req, res) => {
const message = await get(req.params.key).catch((err) => {
if (err) console.error(err)
});
// send response
res.send({
status: 200,
message: message
})
});
// write to redis
app.post('/send', async (req, res) => {
await set(req.body.key, req.body.value);
// send response
res.send({
status: 200,
message: 'Ok'
})
});
app.listen(3000, () => {
console.log('App listening on port 3000!');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment