Skip to content

Instantly share code, notes, and snippets.

@jasheloper
Last active December 3, 2019 13:08
Show Gist options
  • Save jasheloper/0d3b4ed534bdc3cab44b2e77c6a78a2e to your computer and use it in GitHub Desktop.
Save jasheloper/0d3b4ed534bdc3cab44b2e77c6a78a2e to your computer and use it in GitHub Desktop.
Creating a file to will handle all routes related to the user resource.
const express = require('express');
const router = express.Router();
router.get('/', (req, res) => {
res.status(200).send('hello from the GET /users endpoint');
});
router.get('/:id', (req, res) => {
res.status(200).send('hello from the GET /users/:id endpoint');
});
router.post('/', (req, res) => {
res.status(200).send('hello from the POST /users endpoint');
});
module.exports = router;
const express = require('express');
const userRoutes = require('./users/userRoutes');
const productRoutes = require('./products/productRoutes');
const clientRoutes = require('./clients/clientRoutes');
const server = express();
server.use('/users', userRoutes);
server.use('/products', productRoutes);
server.use('/clients', clientRoutes);
server.listen(8000, () => console.log('API running on port 8000'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment