Project is a faster way to building a Node.js RESTful API in TypeScript.
Start use now and just focus on your business and not spending hours in project configuration.
- Beautiful Code thanks to the awesome annotations of the libraries from pleerock.
- Dependency Injection done with the nice framework from TypeDI.
- Simplified Database Query with the ORM TypeORM.
- Clear Structure with different layers such as controllers, services, repositories, models, middlewares...
- Easy Exception Handling thanks to routing-controllers.
- Smart Validation thanks to class-validator with some nice annotations.
- Custom Validators to validate your request even better and stricter (custom-validation-classes).
- Basic Security Features thanks to Helmet.
- Easy event dispatching thanks to event-dispatch.
- Fast Database Building with simple migration from TypeORM.
- Easy Data Seeding with our own factories.
- Auth System thanks to jsonwebtoken.
You need to set up your development environment before you can do anything.
Install Node.js and NPM
- on OSX use homebrew
brew install node
- on Windows use chocolatey
choco install nodejs
Install a MySQL database.
If you work with a mac, i recommend to use DBngin for the installation.
Clone or download this project. Configure your package.json for your new project.
Then copy the .env.example
file and rename it to .env
. In this file you have to add your database connection information.
Create a new database with the name you have in your .env
file.
Then setup your application environment.
npm install
This installs all dependencies with npm. So after that your development environment is ready to use.
Go to the project dir and start your app with this npm script.
npm run dev
This starts a local server using
nodemon
, which will watch for any file changes and will restart the server according to these changes. The server address will be displayed to you ashttp://localhost:3000
.
The route prefix is /api
by default, but you can change this in the .env file.
Route | Description |
---|---|
/api/users | Example entity endpoint |
- Run
npm run typeorm migration:create {name}
to create a new migration file. - To migrate your database run
npm run typeorm migration:run
.
- You may execute the
npm run seed:run
command to seed your database.
Pagination and Sort are implemented on method getAll
for Users
, try to send an api like this: http://localhost:3000/api/users?limit=10&page=1&sortByDesc=id
.
Name | Description |
---|---|
dist/ | Compiled source files will be placed here |
src/ | Source files |
src/config | The config directory, as the name implies, contains all of your application's configuration files. |
src/api/controllers/ | REST API Controllers |
src/api/responses | Response classes or interfaces to type json response bodies |
src/api/exceptions/ | Custom HttpErrors like 404 NotFound |
src/api/middlewares/ | Express Middlewares |
src/api/models/ | TypeORM Models |
src/api/repositories/ | Repository / DB layer |
src/api/services/ | Service layer |
src/api/subscribers/ | Event subscribers |
src/api/validators/ | Request classes with validation rules if the body is not equal with a model |
src/api/transformers/ | Class-transformer allows you to transform plain object to some instance of class and versa |
src/database/factories | Factory the generate fake entities |
src/database/migrations | Database migration scripts |
src/database/seeds | Seeds to create some data in the database |
src/decorators/ | Custom decorators like @EventDispatch |
src/public/ | Static assets (fonts, css, js, img). |
.env.example | Environment configurations |