Skip to main content

Route

route

  • create a folder in the root directory /src/route
  • under this folder, create a file called todos.js
const express = require('express');
const router = express.Router(); //in each route, we cannot use app, but we use router object

router.get('/', (req,res)=>{
res.send('show all todos');
})

module.exports = router;

use route

  • in app.js, now we can import and use this route
//use routes
const bootcamps = require('./src/routes/todos');
app.use('/todos',todos);