A simple Node.js application with one endpoint that returns a "Hello World" message and timestamp in JSON format.
- Express.js REST API
- Docker containerization
- CI/CD with GitHub Action
- Automated tests
- Node.js 18+ (for local development)
- Docker (for containerization)
- GitHub account (for CI/CD)
-
Clone the repository:
git clone https://github.com/yourusername/simple-node-app.git cd simple-node-app
-
Install dependencies:
npm install
-
Start the application:
npm start
-
The API will be available at http://localhost:3000
-
Build the Docker image:
docker build -t simple-node-app .
-
Run the container:
docker run -p 3000:3000 simple-node-app
-
Alternatively, use Docker Compose:
docker-compose up
Run tests with:
npm test
The application is set up for automatic deployment using GitHub Actions. When you push to the main branch, the following happens:
- Tests are run
- A Docker image is built and pushed to Docker Hub
- The image is deployed to your remote server
For the GitHub Actions workflow to function, you need to set up these secrets in your GitHub repository:
DOCKERHUB_USERNAME
: Your Docker Hub usernameDOCKERHUB_TOKEN
: Your Docker Hub access tokenSERVER_HOST
: Your server's hostname or IPSERVER_USERNAME
: SSH username for the serverSERVER_SSH_KEY
: SSH private key for authentication
GET /
: Returns a JSON object with a message and current timestamp
Example response:
{
"message": "Hello World!",
"timestamp": "2023-09-14T12:34:56.789Z"
}