Sign inSign up

reyanshkharga/nodeapp

By reyanshkharga

•Updated 4 months ago

Node.js Express and MongoDB REST API sample application.

Image
0

1.4K

reyanshkharga/nodeapp repository overview

⁠How to use this image

⁠Start a nodeapp server instance

$ docker run --name myNodeApp -d nodeapp:tag

⁠Port the container uses

The container runs on the default port 5000.
You can change it by setting the environment variable PORT to the desired value.

⁠nodeapp:v1

This version of the nodeapp image is a simple Node.js Express application.

⁠Example
docker run --name myContainer -p 5000:5000 reyanshkharga/nodeapp:v1
⁠Routes
GET /
GET /health
GET /random

GET / returns a JSON object containing Host and Version.
GET /health returns the health status.
GET /random returns a random integer between 1 and 10

⁠nodeapp:delay

This version of the nodeapp image is the same as the v1. The only change is that the Express server starts after a delay of 30s.

⁠nodeapp:buggy

This version of the nodeapp image intermittently throws a 502 error intentionally. This version is created to demo the circuit breaker feature of Istio.

⁠nodeapp:mongo

This version of the nodeapp image uses MongoDB to store data.

⁠Environment Variables

MONGODB_URI
POD_NAME

MONGODB_URI is required while POD_NAME is optional.

⁠Example
# without environment variable
docker run --name myContainer --env -p 5000:5000 reyanshkharga/nodeapp:mongo

# with environment variable
docker run --name myContainer --env POD_NAME=myPod MONGODB_URI=mongodb://my-mongodb-service:27017 -p 5000:5000 reyanshkharga/nodeapp:mongo
⁠Routes
GET /
GET /health
GET /random
GET /books
POST /addBook
POST /updateBook
POST /deleteBook
  • GET / returns a JSON object containing Host and Version. If the POD_NAME environment variable is set, the value of the Host will be the value of the variable.
  • GET /health returns the health status.
  • GET /random returns a randomly generated number.
  • GET /books returns the list of books.
  • POST /addBook adds a book.
  • POST /updateBook updates the copies_sold value for the given book id.
  • POST /deleteBook deletes the book record that matches the given id.

Sample body for POST /addBook:

{
    "id": 1,
    "title": "Book1",
    "copies_sold": 0
}

Sample body for POST /updateBook:

{
    "id": 1,
    "copies_sold": 100
}

Sample body for POST /deleteBook:

{
    "id": 1
}

Tag summary

Content type

Image

Digest

sha256:8c6288590…

Size

44.3 MB

Last updated

4 months ago

docker pull reyanshkharga/nodeapp:probes