Skip to content

mattburrell/nodejs-logging-best-practices

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Express Logging Best Practices

This project demonstrates best practices for logging using an Express application using Winston as an example.

Read the accompanying Medium article here.

Features

  • Express: Web framework for Node.js.
  • Winston: Logging library for structured and flexible logging.

Getting Started

Prerequisites

  • Node.js
  • npm (Node package manager)

Installation

  1. Clone the repository:

    git clone https://github.com/mattburrell/nodejs-logging-best-practices
    cd nodejs-logging-best-practices
  2. Install the dependencies:

    npm install

Running the Application

Start the server:

node index.js

Running Tests

Run the tests with Jest:

npm test

Usage

  • 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.

Code Overview

  • server.js: Sets up Express routes and Winston logger.
  • index.js: Starts the server.
  • server.test.js: Contains Jest tests for the server.

Logging

Logs are saved in combined.log and output to the console.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages