Skip to content

Instantly share code, notes, and snippets.

@victorsteven
Created April 20, 2019 18:45
Show Gist options
  • Select an option

  • Save victorsteven/f7051a95554bc8e3e439737bfa55be1b to your computer and use it in GitHub Desktop.

Select an option

Save victorsteven/f7051a95554bc8e3e439737bfa55be1b to your computer and use it in GitHub Desktop.
Root index.js file
import config from 'dotenv';
import express from 'express';
import bodyParser from 'body-parser';
import bookRoutes from './server/routes/BookRoutes';
config.config();
const app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
const port = process.env.PORT || 8000;
app.use('/api/v1/books', bookRoutes);
// when a random route is inputed
app.get('*', (req, res) => res.status(200).send({
message: 'Welcome to this API.',
}));
app.listen(port, () => {
console.log(`Server is running on PORT ${port}`);
});
export default app;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment