https://github.com/trendev/helloworld
simple helloworld example build on NodeJS & Kubernetes
https://github.com/trendev/helloworld
docker kubernetes nodejs
Last synced: about 2 months ago
JSON representation
simple helloworld example build on NodeJS & Kubernetes
- Host: GitHub
- URL: https://github.com/trendev/helloworld
- Owner: trendev
- License: mit
- Created: 2020-03-02T10:42:08.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-10-19T13:13:31.000Z (over 1 year ago)
- Last Synced: 2025-01-14T06:30:19.685Z (over 1 year ago)
- Topics: docker, kubernetes, nodejs
- Language: JavaScript
- Size: 79.1 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Node.js Express Server
This is a simple Node.js application using the Express framework, Docker and Kubernetes. It provides basic health-check routes and retrieves system information such as IP addresses and hostname.
## Features
- **Health check endpoint** to verify the status of the application.
- **System information endpoint** that returns the namespace, hostname, IP address, and a timestamp.
- **Logging** with `morgan` to monitor HTTP requests.
- Uses `os` module to retrieve network interface details.
## Prerequisites
- Node.js (v12.x or higher)
- npm (v6.x or higher)
## Installation
1. Clone this repository.
```bash
git clone
```
2. Navigate to the project directory.
```bash
cd
```
3. Install the dependencies.
```bash
npm install
```
## Environment Variables
The application can use the following environment variables:
- `PORT`: Port on which the server will listen (default is `9000`).
- `MY_POD_NAMESPACE`: The namespace for the pod (defaults to `docker`).
- `MY_POD_NAME`: The hostname of the pod (defaults to system hostname).
- `MY_POD_IP`: The IP address of the pod (defaults to the machine's network interface addresses).
## Usage
1. To start the server, run the following command:
```bash
node index.js
```
2. The application will be running on the port specified by the `PORT` environment variable (or `9000` by default).
## API Endpoints
### GET `/health`
This endpoint returns the health status of the server.
**Response:**
```json
{
"status": "ok",
"message": "we are up and running 😘"
}
```
### GET `/`
This endpoint returns system information such as the namespace, hostname, IP addresses, and a timestamp.
**Response:**
```json
{
"status": "ok",
"namespace": "docker",
"hostname": "",
"ip": [
{ "eth0": "192.168.1.100" }
],
"timestamp": 1684567890123
}
```
## Logging
The server uses the `morgan` library for request logging. Logs are printed in the console in the "dev" format.