Skip to content

Instantly share code, notes, and snippets.

@ChugunovRoman
Created June 21, 2018 12:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChugunovRoman/6051d87faf15c5dd59d93d716e667311 to your computer and use it in GitHub Desktop.
Save ChugunovRoman/6051d87faf15c5dd59d93d716e667311 to your computer and use it in GitHub Desktop.
Simple static server with Expressjs
import path from "path";
import Express from 'express';
const root = process.cwd();
const p = path.resolve(root, 'build');
const app = Express();
app.use(Express.static(p));
app.get('/', (req, res) => {
res.sendFile(`${p}/index.html`, {
headers: {
'Content-Type': 'text/html'
}
});
});
app.listen(process.env.PORT, (err) => {
if (err) throw err;
console.log(`Server is running on localhost:${process.env.PORT}`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment