This is a basic template for an Express API. It includes an example of a simple API to handle books and their authors. All CRUD operations are implemented. The main goal of this project is to provide a starting point for building an Express API. The template includes the following features and tools:
- TypeScript: A typed superset of JavaScript that compiles to plain JavaScript.
- Express: A fast, unopinionated, minimalist web framework for Node.js.
- Docker/Compose: A platform for developing, shipping, and running applications in containers.
- Prisma: A modern database toolkit for TypeScript and Node.js.
- PostgreSQL: A powerful, open-source object-relational database system.
- Zod: A TypeScript-first schema declaration and validation library.
- Jest: A delightful JavaScript Testing Framework with a focus on simplicity.
- Supertest: A high-level abstraction for testing HTTP.
- ESLint: A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript.
- Node.js (v20.16.0 or higher)
- NPM (v10.8.1 or higher)
- Docker (v26.1.3 or higher)
- Docker Compose (v2.27.0 or higher)
- GNU Make (v4.3 or higher)
P.S.: If you are getting an error when running docker commands, you may need to run them with sudo
even the npm run
commands.
- Clone the repository:
git clone https://github.com/mateusvrs/express-tpl.git
- Install the dependencies and run the setup script:
npm install && npm run setup
- Start the development server:
npm run dev
-
Open your browser and navigate to
http://localhost:3000/docs
to see the API in action. -
To stop the development server, run:
npm run stop
# or # to remove volumes
npm run stop:vls
To run the tests, execute the following command:
npm test
The first time you run the tests the docker image will be built, so it may take a little longer. After that, the tests will run faster.
After running the tests the container will be removed as well as the volumes. Although, if something goes wrong and the container is not removed, you can run the following command:
npm run stop:test:vls
The database is managed by Prisma. The current migrations are applied automatically when the container is started. If you need to create a new migration, you can run the following command before starting the container:
P.S.: Replace {text_the_migration_name}
with the name of the migration. The name should be in snake_case.
make migrate name="{text_the_migration_name}"
The project have a pre-configured GitHub Actions workflow that runs the tests on every push to the main branch and uploads the coverage report to Codecov. Also, the workflow runs ESLint to check the code style and apply possible fixes automatically.
If you want to set up the Codecov, you need to create an account on the platform and add the CODECOV_TOKEN
secret to your repository. You can find the token on the Codecov website.
The workflow is simple and can be customized according to your needs.