This project sets up a simple Express.js backend with Winston logging. It supports structured logging to both stdout and optionally Grafana Loki, allowing log monitoring in real-time.
Additionally, an Artillery load test script is provided to simulate different traffic patterns for performance testing.
Ensure you have the following installed:
- Node.js (>=14.x)
- npm (Node Package Manager)
- Grafana & Loki (Optional, for log aggregation)
Run the following command to install the required packages:
npm install
Create a .env file in the project root and define the following variables:
PORT=3000
LOKI_URL=http://localhost:3100
PORT – The port number where the Express server runs (default: 3000). LOKI_URL – If provided, logs will be sent to Loki; otherwise, only stdout logging is enabled.
Start the express server with:
npm start
The server will run on http://localhost:3000
The Artillery load test simulates real-world traffic with:
- A warm-up phase
- A gradual increase in load
- A sustained high traffic period
- A sudden traffic spike
- A cool-down phase
To start the load test, run:
npm run load-test
This will execute requests against the /items endpoint, logging results in both stdout and Loki (if configured).
- All logs are printed to the terminal (stdout).
- If LOKI_URL is set, logs are also sent to Grafana Loki for centralized monitoring.
- Errors (e.g., duplicate items) are logged as error messages in Winston.
- Cannot connect to Loki? Ensure Loki is running and LOKI_URL is correctly set.
- Load test fails? Check if the server is running before executing npm run load-test.
- Duplicate item error? The backend prevents duplicate names, and logs an error if one exists.
- Background
- What is Observability? | Grafana for Beginners Ep. 1 2. What is DevOps? | Grafana for Beginners Ep.2
- Setting up:
- Set up a new Grafana Cloud Account | Grafana for Beginners Ep. 5 - YouTube
- Loki - To store logs
- Sending logs to Loki
- Winston - Logging in JavaScript & Node.js applications
- Winston-Loki transport:
- winston - npm
- winston-loki - npm
- Connecting Grafana to Loki
- Creating dashboard:
- Exploring logs, metrics, and traces with Grafana | Grafana for Beginners Ep. 7
- Most commonly used visualizations in Grafana | Grafana for Beginners Ep. 8
- Creating visualizations with Grafana | Grafana for Beginners Ep. 9