A simple Node.js "Hello World" API with beautiful and informative terminal logging using Winston.
- Framework: Node.js with Express
- Logging: Winston for beautiful, colorized console logs
- Scripts:
npm startto run the server - Endpoint:
GET /returns "Hello World!"
-
Install dependencies:
npm install
-
Start the server:
npm start
The server will start on
http://localhost:3000.
The logging is configured in logger.js using the Winston library.
logger.js: This file sets up a custom Winston logger.- It uses
winston.format.combineto chain together several formatting options. colorize(): Applies colors to the entire log message.timestamp(): Adds a timestamp in the formatYYYY-MM-DD hh:mm:ss.SSS A.align(): Aligns the log messages.printf(): A custom print function to format the final log output as[timestamp] level: message.
- It uses
index.js: This file uses the logger to log incoming requests and server status.- A middleware is used to log every incoming request with its method and URL.
- A log message is printed when the server starts successfully.
[2025-07-17 12:33:57.622 PM] info: Server is running on http://localhost:3000
[2025-07-17 12:34:00.121 PM] info: Request received: GET /