Created
December 28, 2017 21:23
-
-
Save aramkoukia/84bcd704d96ada07296e3881a2b65750 to your computer and use it in GitHub Desktop.
MEVN Stack index js
This file contains hidden or 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 bodyParser = require('body-parser'); | |
| const routes = require('./server/routes'); | |
| const publicWeb = process.env.PUBLICWEB; | |
| const app = express(); | |
| app.use(bodyParser.json()); | |
| app.use(bodyParser.urlencoded({ extended: false })); | |
| app.use(express.static(publicWeb)); | |
| console.log(`serving ${publicWeb}`); | |
| app.use('/api', routes); | |
| app.get('*', (req, res) => { | |
| res.sendFile(`index.html`, { root: publicWeb }); | |
| }); | |
| const port = process.env.SERVER_PORT; | |
| app.listen(port, () => console.log(`API running on http://localhost:${port}`)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment