Skip to content

hackykitty/sapia-backend-code

Repository files navigation

Sapia Backend Code(Test)

This repo is to demonstrate to build a simple express(typescript) based server for logging with JWT authtoken, Unit Test with Jest, Integration Test with supertest, MongoDB Unit Test with mongodb-memory-server and dockerization.

Features

  • Express(Typescript)
  • JWT authentication
  • Unit Test/Integration Test
  • SwaggerUI
  • Dockerization

Installation & Development

This project requires Node.js v14+ and Docker to run Install the dependencies and devDependencies and start the server.

cd sapia-backend-code
yarn install
sudo ./scripts/run_dev_dbs.sh -r #run mongodb docker image
yarn dev
open http://localhost:3000/swagger

For production environments...

cd sapia-backend-code
yarn install --production
sudo ./scripts/run_dev_dbs.sh -r #run mongodb docker image
yarn build
yarn start
open http://localhost:3000/swagger

For integration test...

yarn test:unit --coverage

Docker

Sapia Backend Code is very easy to install and deploy in a Docker container.

By default, the Docker will expose port 8080, so change this within theDockerfile if necessary. When ready, simply use the Dockerfile tobuild the image.

cd sapia-backend-code
docker build -t <youruser>/sapia-backend-code:${package.json.version} .

This will create the sapia-backend-code image and pull in the necessary dependencies. Be sure to swap out ${package.json.version} with the actual version of sapia-backend-code.

Once done, run the Docker image and map the port to whatever you wish on your host. In this example, I simply map port 3000 of the host to port 3000 of the Docker (or whatever port was exposed in the Dockerfile):

sudo docker run --rm -p 3000:3000 --name sapia-backend-code -e MONGO_URL=mongodb://localhost/exmp sapia-backend-code:${package.json.version}

Note: MONGO_URL=mongodb://localhost/exmp is required for MongoDB service.

Verify the deployment by navigating to your server address in your preferred browser.

http://localhost:3000/swagger

Docker Cluster

You can push the sapia-backend-code docker image to your Docker hub repository (private or public) to run it on any node where docker is installed. It is downloaded automatically when you try to run it for the first time. A public sapia-backend-code repository is already created.

To run Docker Cluster on your machine, you just need to run the following command.

sudo ./scripts/run.sh

Verify the deployment by navigating to your server address in your preferred browser.

http://sapia-backend-code.local/swagger

License

MIT

Good educational project

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published