There are times when you might need to know information about your running NodeJS server. Here is a simple way to create an endpoint to expose valuable system for your production NodeJS application. Being able to quickly access system information allows for quick troubleshooting and triaging of potential issues.
In this short post I’ll walk through creating a simple endpoint to access system information.
NodeJS has a built in
os module that gives access to valuable information about the underlying operating system of your NodeJS server. This could include information about the operating system platform, server uptime, CPUs, etc. Depending on your use case this could reveal valuable information for maintenance and troubleshooting. Using the
os.platform() method we will return platform information about the OS. There is a lot of other information available, take your pick.
Here is a simple NodeJS/ ExpressJS server with a single
GET /maintenance endpoint.
NOTE: This endpoint MUST REQUIRE user authorization
const express = require('express');