Skip to content

Instantly share code, notes, and snippets.

@aramkoukia
Created December 28, 2017 21:23
Show Gist options
  • Select an option

  • Save aramkoukia/84bcd704d96ada07296e3881a2b65750 to your computer and use it in GitHub Desktop.

Select an option

Save aramkoukia/84bcd704d96ada07296e3881a2b65750 to your computer and use it in GitHub Desktop.
MEVN Stack index js
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