Multiple purpose logging example on Nodejs express system by customizing winston.
- Typescript base
- using Winston module
- MongoDB error logging
- logging to console and file(json)
- logging HTTP request context
- Node v18.0 above
- MongoDB v6.0
- Install module
# yarn
yarn install
# npm
npm install- Setup
Edit .env file:
MONGO_URL=mongodb://localhost:27017/sampleDB
- Launch server
If using VSCode, show the Run and Debug view and launch Start server from Debugging start menu.
If using command, input below.
# yarn
yarn dev
# npm
npm run devStart the development server on http://localhost:3000
with logging files in logs directory.
- Edit
.envfile for production:
NODE_ENV=production
- Build application:
# yarn
yarn build
# npm
npm run build- Launch application:
# yarn
yarn start
# npm
npm start