This project demonstrates best practices for logging using an Express application using Winston as an example.
Read the accompanying Medium article here.
- Express: Web framework for Node.js.
- Winston: Logging library for structured and flexible logging.
- Node.js
- npm (Node package manager)
-
Clone the repository:
git clone https://github.com/mattburrell/nodejs-logging-best-practices cd nodejs-logging-best-practices
-
Install the dependencies:
npm install
Start the server:
node index.js
Run the tests with Jest:
npm test
- Access the service at
http://localhost:3000/process-order/:orderId
. - Replace
:orderId
with the order ID you want to process. - To simulate an error use a non-numeric order ID.
server.js
: Sets up Express routes and Winston logger.index.js
: Starts the server.server.test.js
: Contains Jest tests for the server.
Logs are saved in combined.log
and output to the console.
This project is licensed under the MIT License - see the LICENSE file for details.