Skip to content

Commit c125efc

Browse files
author
hirsch88
committed
Merge branch 'release/2.0.0-beta'
2 parents b23e0c2 + 14755d2 commit c125efc

File tree

118 files changed

+3066
-1348
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+3066
-1348
lines changed

.env.example

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@
44
APP_NAME=express-typescript-boilerplate
55
APP_ENV=local
66
APP_HOST=http://localhost
7-
APP_URL_PREFIX=/api/v1
7+
APP_URL_PREFIX=/api
88
APP_PORT=3000
99

1010
#
1111
# LOGGING
1212
#
13-
DEBUG=app*,api*,core*
1413
LOG_LEVEL=debug
1514
LOG_ADAPTER=winston
1615

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,8 @@ dist/
2828

2929
# Generated source-code #
3030
src/**/*.js
31+
src/**/*.js.map
3132
test/**/*.js
33+
test/**/*.js.map
3234
coverage/
35+
!test/preprocessor.js

.vscode/launch.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
"type": "node",
99
"request": "launch",
1010
"name": "Debug",
11-
"program": "${workspaceRoot}/dist/index.js",
11+
"program": "${workspaceRoot}/src/app.js",
1212
"smartStep": true,
1313
"outFiles": [
14-
"../dist/**/*.js"
14+
"../src/**/*.js"
1515
],
1616
"protocol": "inspector",
1717
"preLaunchTask": "build",

Procfile

Lines changed: 0 additions & 1 deletion
This file was deleted.

README.md

Lines changed: 99 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,39 @@
11
# Express Typescript Boilerplate
22
[![Dependency Status](https://david-dm.org/w3tecch/express-typescript-boilerplate/status.svg?style=flat)](https://david-dm.org/w3tecch/express-typescript-boilerplate) [![Build Status](https://travis-ci.org/w3tecch/express-typescript-boilerplate.svg?branch=master)](https://travis-ci.org/w3tecch/express-typescript-boilerplate)
33

4-
A delightful way to building a RESTful API with NodeJs & TypeScript.
4+
> A delightful way to building a RESTful API with NodeJs & TypeScript.
5+
6+
> An Node.js RESTful API boilerplate featuring
7+
[Express](https://expressjs.com/),
8+
[Inversify](http://inversify.io/),
9+
[Winston](https://github.com/winstonjs/winston),
10+
[TypeScript](https://www.typescriptlang.org/),
11+
[TsLint](http://palantir.github.io/tslint/),
12+
[@types](https://www.npmjs.com/~types),
13+
[Jest](https://facebook.github.io/jest/),
14+
[Swagger](http://swagger.io/),
15+
[validatejs](https://validatejs.org/),
16+
[knex](http://knexjs.org/) and
17+
[bookshelf](http://bookshelfjs.org/)
18+
by [w3tech](https://github.com/w3tecch)
19+
20+
## Why
21+
Our main goal with this project is a feature complete server application.
22+
We like you to be focused on your business and not spending hours in project configuration.
23+
24+
Try it!! We are happy to hear your feedback or any kind of new features.
25+
26+
## Features
527
- **Beautiful Syntax** thanks to the awesome annotations from [Inversify Express Utils](https://github.com/inversify/inversify-express-utils).
628
- **Easy API Testing** with included black-box testing.
729
- **Dependency Injection** done with the nice framework from [Inversify](http://inversify.io/).
830
- **Fast Database Building** with simple migration and seeding from [Knex](http://knexjs.org/).
931
- **Simplified Database Query** with the ORM of [Knex](http://knexjs.org/) called [Bookshelf](http://bookshelfjs.org/).
1032
- **Clear Structure** with controllers, services, repositories, models, middlewares...
11-
- **Easy Exception Handling** with our own simple classes. You will see.
33+
- **Easy Exception Handling** with our own simple and easy to adopt logic. You will love it.
1234
- **Easy Data Seeding** with our own factories.
13-
- **Custom Commands** are also available in our setup and really easy to use.
35+
- **Custom Commands** are also available in our setup and really easy to use or even extend.
36+
- **Scaffolding Commands** will speed up your development tremendously as you should focus on business code and not scaffolding.
1437
- **Smart Validation** thanks to [class-validator](https://github.com/pleerock/class-validator) with some nice annotations.
1538
- **API Documentation** thanks to [swagger](http://swagger.io/).
1639
- **API Monitoring** thanks to [express-status-monitor](https://github.com/RafalWilinski/express-status-monitor).
@@ -26,16 +49,18 @@ A delightful way to building a RESTful API with NodeJs & TypeScript.
2649
### Installing
2750
* `fork` this repo
2851
* `clone` your fork
29-
* `yarn install` to install all dependencies and typings
30-
* Create new database. You will find the name in the .env files.
31-
* `npm run db:migrate` to create the schema
32-
* `npm run db:seed` to insert some test data
33-
* `npm run serve` to start the dev server in another tab
52+
* `cp .env.example .env` to copy the example .env file and enter your database connection
53+
* Create a new database. You will find the name in the .env file.
54+
* Run `npm run setup` or enter the following commands manually:
55+
* `yarn install` to install all dependencies and typings.
56+
* `npm run db:migrate` to create the schema.
57+
* `npm run db:seed` to insert some test data.
58+
* `npm run serve` to start the application.
3459

3560
### Running the app
36-
After you have installed all dependencies you can now run the app.
37-
Run `npm run serve` to start a local server using `nodemon` which will watch for changes and then will restart the sever.
38-
The port will be displayed to you as `http://0.0.0.0:3000` (or if you prefer IPv6, if you're using `express` server, then it's `http://[::1]:3000/`).
61+
After you have installed all dependencies you can run the app.
62+
Enter `npm run serve` to start a local server using `nodemon`, which will watch for any file changes and will restart the sever according to these changes.
63+
The server address will be displayed to you as `http://0.0.0.0:3000`.
3964

4065
## Scripts / Tasks
4166
All script are defined in the package.json file, but the most important ones are listed here.
@@ -44,91 +69,111 @@ All script are defined in the package.json file, but the most important ones are
4469
* Install all dependencies with `yarn install`
4570

4671
### Linting
47-
* Run code analysis using `npm run lint`. This runs tslint.
48-
* There is also a vscode task for this called lint.
72+
* Run code quality analysis using `npm run lint`. This runs tslint.
73+
* There is also a vscode task for this called `lint`.
4974

5075
### Tests
51-
* Run the unit tests using `npm test`.
76+
* Run the unit tests using `npm test` (There is also a vscode task for this called `test`).
5277
* Run the black-box tests using `npm run test:black-box` and don't forget to start your application and your [Auth0 Mock Server](https://github.com/hirsch88/auth0-mock-server).
53-
* There is also a vscode task for this called test.
5478

5579
### Running in dev mode
56-
* Run `npm run serve` to start nodemon with ts-node, which will serve your app.
80+
* Run `npm run serve` to start nodemon with ts-node, to serve the app.
5781
* The server address will be displayed to you as `http://0.0.0.0:3000`
5882

5983
### Building the project and run it
60-
* Run `npm run build` to generated all JavaScript files from your TypeScript sources. After this step you can deploy the app on any server.
61-
* There is also a vscode task for this called build.
62-
* To start the builded app use `npm start`.
84+
* Run `npm run build` to generated all JavaScript files from the TypeScript sources (There is also a vscode task for this called `build`).
85+
* To start the builded app located in `dist` use `npm start`.
6386

6487
### Database
65-
* Run `npm run db:migrate` to migration the new schema to the database
66-
* Run `npm run db:migrate:rollback` to rollback one version
67-
* Run `npm run db:seed` to seed some data into the database
68-
* Run `npm run db:reset` to clean the database and migrate again
88+
* Run `npm run db:migrate` to migrate schema changes to the database
89+
* Run `npm run db:migrate:rollback` to rollback one migration
90+
* Run `npm run db:seed` to seed sample data into the database
91+
* Run `npm run db:reset` to rollback all migrations and migrate any migration again
6992

7093
### Console
71-
* To run your own created cli script enter `npm run console <command-name>`
94+
* To run your own created command enter `npm run console <command-name>`.
95+
* This list all your created commands `npm run console:help`.
96+
97+
### Scaffolding Commands
98+
All the templates for the commands are located in `src/console/templates`.
99+
100+
* `npm run console make:resource <file>` - Generates a controller, service, requests, repo, model and a migration with CRUD operations.
101+
* `npm run console make:controller <file>` - Generates a controller.
102+
* `npm run console make:service <file>` - Generates a service.
103+
* `npm run console make:repo <file>` - Generates a repository.
104+
* `npm run console make:model <file>` - Generates a model with the props and configurations.
105+
* `npm run console make:middleware <file>` - Generates a basic middleware.
106+
* `npm run console make:request <file>` - Generates a basic request.
107+
* `npm run console make:listener <file>` - Generates a basic listener.
108+
* `npm run console make:exception <file>` - Generates a basic exception.
109+
* `npm run console update:targets <file>` - Reads all the API files and generate a new `constants/Targets.ts` file out of it.
110+
111+
**Example**
112+
```
113+
$ npm run console make:controller auth/auth
114+
// -> creates `api/controllers/auth/AuthController.ts
115+
116+
$ npm run console make:model user
117+
// -> creates `api/models/User.ts
118+
```
72119

73120
## IoC
74121
Our IoC automatically looks through the `controllers`, `listeners` , `middlewares`, `services`,
75-
`repositories` and `models` for files to bind to our IoC - Container. So you have nothing to do.
122+
`repositories` and `models` folders in `src/api/` for files to bound automatically into the IoC - Container, so you have nothing to do.
76123

77-
However it is very important to keep the naming, because otherwise our IoC will not find your
78-
created file.
124+
**However it is very important to keep the naming right, because otherwise our IoC will not find your
125+
created files!!**
79126

80127
## Using the debugger in VS Code
81128
Just set a breakpoint and hit `F5` in your Visual Studio Code.
82129

83130
## API Routes
84-
The route prefix is by default `/api/v1`, but you can change this in the .env.example file.
131+
The route prefix is `/api` by default, but you can change this in the .env file.
85132

86133
| Route | Description |
87134
| ----------- | ----------- |
88-
| **/info** | Shows us the name, description and the version of the package.json |
89-
| **/docs** | This is the Swagger UI with our API Documentation |
90-
| **/status** | Shows a small monitor app for our API |
135+
| **/api/info** | Shows us the name, description and the version of the package.json |
136+
| **/api/docs** | This is the Swagger UI with our API documentation |
137+
| **/status** | Shows a small monitor page for the server |
91138

92139
## Project Structure
93140

94141
| Name | Description |
95142
| ----------------------------- | ----------- |
96143
| **.vscode/** | VSCode tasks, launch configuration and some other settings |
97-
| **build/** | Task Runner configurations and tasks |
98144
| **dist/** | Compiled source files will be placed here |
99-
| **src/** | Source-Files |
100-
| **src/api/controllers/** | REST-API - Controllers |
145+
| **src/** | Source files |
146+
| **src/api/controllers/** | REST API Controllers |
101147
| **src/api/exceptions/** | Exceptions like 404 NotFound |
102-
| **src/api/listeners/** | Event-Listeners |
148+
| **src/api/listeners/** | Event listeners |
103149
| **src/api/middlewares/** | Express Middlewares like populateUser |
104150
| **src/api/models/** | Bookshelf Models |
105-
| **src/api/repositories/** | Repository Layer |
106-
| **src/api/requests/** | Request Bodys with Validations |
107-
| **src/api/services/** | Service Layer |
108-
| **src/api/** swagger.json | Swagger Documentation |
109-
| **src/console/** | Command Line scripts |
151+
| **src/api/repositories/** | Repository / DB layer |
152+
| **src/api/requests/** | Request bodys with validations |
153+
| **src/api/services/** | Service layer |
154+
| **src/api/** swagger.json | Swagger documentation |
155+
| **src/console/** | Command line scripts |
110156
| **src/config/** | Configurations like database or logger |
111157
| **src/constants/** | Global Constants |
112-
| **src/core/** | Our small framework |
113-
| **src/database/factories/** | Model Factories to generate database records |
114-
| **src/database/migrations/** | Migrations scripts to build up our database schema |
115-
| **src/database/seeds/** | Seed scripts to fake some data into our database |
158+
| **src/core/** | The core framework |
159+
| **src/database/factories/** | Model factories to generate database records |
160+
| **src/database/migrations/** | Migrations scripts to build up the database schema |
161+
| **src/database/seeds/** | Seed scripts to fake sample data into the database |
116162
| **src/public/** | Static assets (fonts, css, js, img). |
117-
| **src/types/** *.d.ts | Custom Type Definitions and files that aren't on DefinitelyTyped |
118-
| **test** | All our test cases |
119-
| **test/setup/** | Some setup scripts to create a needed test environment |
120-
| **test/black-box/** *.test.ts | Black-Box Testing (like e2e) |
121-
| **test/unit/** *.test.t | Unit Testing |
122-
| .env.example | All environment configurations |
163+
| **src/types/** *.d.ts | Custom type definitions and files that aren't on DefinitelyTyped |
164+
| **test** | Tests |
165+
| **test/black-box/** *.test.ts | Black-Box tests (like e2e) |
166+
| **test/unit/** *.test.ts | Unit tests |
167+
| .env.example | Environment configurations |
123168
| knexfile.ts | This file is used for the migrations and seed task of knex |
124169

125170
## Related Projects
126171
* [Microsoft/TypeScript-Node-Starter](https://github.com/Microsoft/TypeScript-Node-Starter) - A starter template for TypeScript and Node with a detailed README describing how to use the two together.
127172
* [express-graphql-typescript-boilerplate](https://github.com/w3tecch/express-graphql-typescript-boilerplate) - A starter kit for building amazing GraphQL API's with TypeScript and express by @w3tecch
128173
* [aurelia-typescript-boilerplate](https://github.com/w3tecch/aurelia-typescript-boilerplate) - An Aurelia starter kit with TypeScript
129-
* [Auth0 Mock Server](https://github.com/hirsch88/auth0-mock-server)
174+
* [Auth0 Mock Server](https://github.com/hirsch88/auth0-mock-server) - Useful for black-box testing or faking an oAuth server
130175

131-
## Documentations
176+
## Documentations of our main dependencies
132177
* [Express](https://expressjs.com/)
133178
* [Knex](http://knexjs.org/)
134179
* [Bookshelf](http://bookshelfjs.org/)
@@ -137,11 +182,11 @@ The route prefix is by default `/api/v1`, but you can change this in the .env.ex
137182
* [Inversify Express Utils](https://github.com/inversify/inversify-express-utils)
138183
* [class-validator](https://github.com/pleerock/class-validator)
139184
* [Jest](http://facebook.github.io/jest/)
140-
* [Auth0 API Documentation](https://auth0.com/docs/api/management/v2#!/Users/get_users)
185+
* [Auth0 API Documentation](https://auth0.com/docs/api/management/v2)
141186
* [swagger Documentation](http://swagger.io/)
142187

143188
## License
144189
[MIT](/LICENSE)
145190

146191
---
147-
Made with ♥ by Gery Hirschfeld ([@GeryHirschfeld1](https://twitter.com/GeryHirschfeld1)) and [contributors](https://github.com/w3tecch/express-typescript-boilerplate/graphs/contributors)
192+
Made with ♥ by w3tech ([w3tech](https://github.com/w3tecch)), Gery Hirschfeld ([@GeryHirschfeld1](https://twitter.com/GeryHirschfeld1)) and [contributors](https://github.com/w3tecch/express-typescript-boilerplate/graphs/contributors)
File renamed without changes.

nodemon.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"ts": "./node_modules/.bin/ts-node"
55
},
66
"events": {
7-
"start": "./node_modules/.bin/tslint -c ./tslint.json 'src/**/*.ts' --format stylish --force",
7+
"start": "./node_modules/.bin/tslint -c ./tslint.json -t stylish 'src/**/*.ts'",
88
"restart": "osascript -e 'display notification \"restarting server\" with title \"node.js application\"'"
99
}
1010
}

0 commit comments

Comments
 (0)