This repository is a dummy Node.js REST-API built with TypeScript and Express. You might want to use it as codebase for your own Node project.
You can find a detailed explanation about the application's architecture on my blog.
A shortened list of the Node modules used in this app:
- ACL (access control list)
- Component-based architecture
- Caching (Redis)
- DB seeding
- Mailing
- MySQL
- Testing
Read more here.
src/api
everything needed for the REST APIsrc/api/components
component routers, controllers, models, tests and moresrc/api/middleware
API middleware
src/config
global configuration filessrc/services
services for sending mails, caching, authentication and moresrc/test
test factory
Requirements:
Installation:
- Run
npm install
- Rename
.env.example
to.env
and enter environment variables - Run
npm run build
to compile the TS code - Run
npm start
to start the application
You can reach the server at http://localhost:3000/api/v1/.
Requirements:
Installation:
- Rename
.env.docker.example
to.env.docker
and enter environment variables - Run
docker-compose up
to start the Docker containers
You can reach the server at http://localhost:3000/api/v1/.
During the build process the following tasks are executed:
- Compiling TS into JS
- Copying mail HTML templates to
dist
directory - Merging component
policy.json
files into a single one indist/output/policies.combined.json
The last two tasks are executed using Gulp as you can see in gulpfile.js
.
In db/seed.sql
you'll find a SQL script that can be used for seeding the database with dummy data. Make sure that the database and its tables were created before executing the script. The tables are created on application start.
You can load the script via a npm command: npm run seed
. If you want to seed the database from a Docker container you must connect to it before: docker exec -it expressjs-api bash
.
Read more about database seeding on my blog.
This application uses acl for permission management. Each component in src/api/components
has its own policy.json
which includes permissions for each role.
During the build process all these policy.json
files get merged into a single one using a Gulp task as described more above.
MailHog is an email testing tool for developers. You can use it as SMTP server to simulate the process of sending mails. MailHog is included as Docker image within the docker-compose.yml
file.
Start the containers as described above and you can open the MailHog web interface at http://localhost:8025 where you'll find an overview of all sent emails.