Last active
January 23, 2018 14:47
-
-
Save barmatz/f9b987de86b055db7a58 to your computer and use it in GitHub Desktop.
Basic Express server
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 { Logger, transports: { Console } } = require('winston'); | |
| module.exports = new ]Logger({ | |
| transports: [ | |
| new Console({ | |
| colorize: true, | |
| level: process.env.NODE_ENV === 'development' ? 'silly' : 'info' | |
| }) | |
| ] | |
| }); |
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 chalk = require('chalk'), | |
| express = require('express'), | |
| morgan = require('morgan'), | |
| logger = require('./logger'), | |
| app = express(), | |
| { env: { PORT, NODE_ENV } } = process, | |
| server = app.listen(PORT || 3000, function () { | |
| const { address, port } = server.address(); | |
| logger.info(`Server start at ${chalk.cyan(`${address}:${port})}`); | |
| }); | |
| switch (NODE_ENV) { | |
| case 'development': | |
| logger.info('Running server in development mode'); | |
| app.use(morgan('dev')); | |
| break; | |
| default: | |
| app.use(morgan('common')); | |
| break; | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment