-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
41 lines (32 loc) · 1.11 KB
/
Copy pathindex.js
File metadata and controls
41 lines (32 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import express from 'express';
import morgan from 'morgan';
import winston from 'winston';
const app = express();
const port = 3000;
const logger = winston.createLogger({
level: 'info',
format: winston.format.json(),
defaultMeta: { service: 'user-service' },
transports: [
//
// - Write to all logs with level `info` and below to `combined.log`
// - Write all logs error (and below) to `error.log`.
//
new winston.transports.File({ filename: 'logs/error.log', level: 'error' }),
new winston.transports.File({ filename: 'logs/combined.log' }),
],
});
if (process.env.NODE_ENV !== 'production') {
app.use(morgan('dev'));
logger.add(new winston.transports.Console({
format: winston.format.simple(),
}));
}
// Routes
app.get('/', (req, res) => res.send('Hello World!'));
app.post('/', (req, res) => res.send('POST request!'));
app.put('/', (req, res) => res.send('PUT request!'));
app.delete('/', (req, res) => res.send('DELETE request!'));
app.all('/all', (req, res) => res.send('All Routes'));
// Start server
app.listen(port, () => logger.log('info', `Started on port ${port}!`));