Skip to content

Instantly share code, notes, and snippets.

@pbabbott
Created August 8, 2018 21:26
Show Gist options
  • Save pbabbott/cfb9c766f5a9d3f741aa23b12c28b3ea to your computer and use it in GitHub Desktop.
Save pbabbott/cfb9c766f5a9d3f741aa23b12c28b3ea to your computer and use it in GitHub Desktop.
Example node server
import express from 'express';
import dotenv from 'dotenv';
import path from 'path';
const getConfigValue = (name, defaultValue) => {
let result = process.env[name];
return result ? result : defaultValue;
}
// Read configuration
dotenv.config({ silent: true });
let config = {
port: getConfigValue('PORT', 3000)
}
// Express server
const server = express();
const indexHtml = path.resolve(__dirname, 'index.html');
server.get('/*', (req, res) => {
res.sendFile(indexHtml);
});
server.listen(config.port, () => {
console.log('Express server successfully started');
});
export default server;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment