This file contains 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
app.get('/api/todo/:key', (req, res, next) => { | |
todos.findOne({ key: req.params.key }) | |
.then(result => { | |
if (!result) { | |
return next({ status: 404, message: 'not found' }); | |
} | |
res.status(200).json(result); | |
}) | |
.catch(err => { | |
return next({ status: 500, message: err.message }); |
This file contains 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
const express = require('express'); | |
const app = express(); | |
let nextId = 1; | |
let todos = []; | |
function addTodo(text) { | |
const id = nextId; | |
todos = [...todos, { | |
id, |