A template for creating new templates.
Below is a quick outline of the structure of the app:
.
├── api # API endpoints
| ├── some-endpoint
| | | ├── controller.ts # Calls the service methods and handles responses
| | | ├── router.ts # Sets up the router and all the available routes
| | | └── service.ts # Handles the more granular parts; DB actions, remote requests etc.
| │ └── ...
├── constants # Constants to use throughout the service
│ └── ...
├── errors # Error classes and helpers
│ └── ...
├── middlewares # Custom Express middlewares
│ └── ...
├── models # ORM-odels
│ └── ...
├── modules # Modules are used to separate code to make it more testable
| ├── some-module
| | ├── doesSomethingCool.ts
| | ├── index.ts
| │ └── ...
│ └── ...
├── types # TypeScript types & interfaces
│ └── ...
├── utils # Utility functions
│ └── ...
├── index.ts # Entrypoint - starts the server
└── server.ts # This is where the Express app is setup and configured
- Install NodeJS 14.15.1+.
- Install Yarn.
- Install Docker.
- Install the dependencies:
yarn install
- Simply run:
yarn start
- You can check the API is running using the following cURL command:
curl -X GET http://localhost:${PORT}/healthcheck
- Simply run the command:
yarn test
This will build and run a Postgres docker image and run the tests against it.
When building the Docker image, we want to inject env vars at build time, as the Dockerfile
injects the build args as env vars into the container.
docker build \
-t kieranroneill/new_service_template \
--build-arg log_level=error \
--build-arg node_env=production \
--build-arg port=3000 \
--build-arg service_name=new-service-template \
--build-arg version=1.0.0 \
.
docker run \
--name new_service_template \
-it \
-p 1337:${PORT} \
kieranroneill/new_service_template:latest