Because it's hard to memorize boilerplates...
Last active
September 6, 2020 07:31
-
-
Save sydcanem/8c5d3577503fe49511a513a6d27842b3 to your computer and use it in GitHub Desktop.
Express ES6 Boilerplate
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
import { Router } from 'express'; | |
export default function() { | |
const api = Router(); | |
api.post('/echo', (req, res) => { | |
res.status(204).send('No content'); | |
}); | |
return api; | |
} |
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
import express from 'express'; | |
import path from 'path'; | |
import cors from 'cors'; | |
import bodyParser from 'body-parser'; | |
import api from './api'; | |
const app = express(); | |
app.use(express.static(path.join(__dirname, '../public'))); | |
app.use(cors()); | |
app.use(bodyParser()); | |
app.use('/api', api()); | |
export default app; |
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
import http from 'http'; | |
import app from './app'; | |
const server = http.createServer(app); | |
socket(server); | |
server.listen(3000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment