If you’re looking to kickstart your backend development using Node.js, you’ve come to the right place! This guide walks you through setting up the Express TypeScript Boilerplate, which comes pre-loaded with Docker and Continuous Integration/Continuous Deployment (CICD) optimizations. Let’s dive in!
What’s Included in This Boilerplate?
This boilerplate isn’t just a simple template; it’s more like a vibrant toolbox ready for crafting your backend masterpiece. Here’s what it contains:
- Github Actions Workflows: Pre-configured automated builds and image publishing.
- Dockerfile: Generate docker builds effortlessly.
- docker-compose: Start services in production mode smoothly.
- Containerized MongoDB: Easy local Mongo container setup with data persistence.
- Safe Mongoose Connection: A reliable helper class for connecting to MongoDB.
- Joi: For straightforward payload validation.
- OpenAPI 3.0 Spec: Documentation starter template for your API.
- Winston Logger: For robust application logging.
- Testing with Jest: Run your tests with ease.
I. Installation
Let’s set up our project!
Using Curl
$ bash (curl -s https://raw.githubusercontent.com/sidhantpanda/public/master/scripts/generate-express-ts-app.sh)
Manual Method
- Clone the repository:
$ git clone git@github.com:sidhantpanda/docker-express-typescript-boilerplate.git your-app-name
$ cd your-app-name
$ yarn install
II. Configuration
Next, we need to update the Docker repository for actions:
$ yarn setup-actions
III. Development
Starting the development server is straightforward. It boots up MongoDB as a service within a Docker container using the compose script.
$ yarn dev
This command will launch:
- API Server: Running at localhost:3000.
- Swagger UI: Documentation at localhost:3000/dev/api-docs.
- MongoDB: Accessible at mongodb:localhost:27017.
IV. Packaging and Deployment
While you can use the mongo container only in the development environment, here’s how to package and deploy your application:
1. Build and Run without Docker:
$ yarn build && yarn start
2. Run with Docker:
$ docker build -t api-server .
3. Run with Docker-Compose:
$ docker-compose up
V. Environment Configuration
To modify environment variables, create a .env
file and start with the contents from .env.default
. Some variables include:
- NODE_ENV: Environment (development/production).
- PORT: The port on which the API server runs (default is 3000).
- MONGO_URL: MongoDB connection URL.
Troubleshooting
Despite thorough preparation, you might face some bumps along the way. If you can’t connect to MongoDB, check if your Docker is running properly or review the .env
configurations. Make sure the required ports are exposed!
For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.
Logging and Monitoring
This application logs using Winston, with logs stored in the .logs
directory and neatly formatted in the console. You can monitor and trace issues efficiently!
Conclusion
At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.