|
| 1 | +# NestJS Playground - API Movie Schedule (rams) |
| 2 | + |
| 3 | +## Stack |
| 4 | + |
| 5 | +**NodeJS**: https://nodejs.org/en/ |
| 6 | + |
| 7 | +**Nest**: https://nestjs.com/ |
| 8 | +``` |
| 9 | +A progressive Node.js framework for building efficient and scalable server-side applications on top of TypeScript & JavaScript (ES6 / ES7 / ES8) heavily inspired by Angular |
| 10 | +``` |
| 11 | + |
| 12 | +**TypeORM**: http://typeorm.io |
| 13 | +``` |
| 14 | +TypeORM is an ORM that can run in NodeJS, Browser, Cordova, PhoneGap and Ionic platforms and can be used with TypeScript and JavaScript (ES5, ES6, ES7) |
| 15 | +``` |
| 16 | + |
| 17 | +**MariaDB**: https://mariadb.org/ |
| 18 | + |
| 19 | +**Docker**: https://www.docker.com/ |
| 20 | + |
| 21 | +## Requirements |
| 22 | + |
| 23 | +### Install NodeJS and npm |
| 24 | +- [Download](https://nodejs.org/en/download/) |
| 25 | +- [Install via package manager](https://nodejs.org/en/download/package-manager/) |
| 26 | + |
| 27 | +### Install Docker and docker-compose |
| 28 | +- https://docs.docker.com/installation |
| 29 | +- https://docs.docker.com/compose/install/ |
| 30 | +- [Manage Docker as a non-root user](https://docs.docker.com/engine/installation/linux/linux-postinstall/#manage-docker-as-a-non-root-user) |
| 31 | + |
| 32 | +## Configuration files |
| 33 | + |
| 34 | +You have to create your own `.env` file, avoiding sharing password, and customizing depending on your own dev environment. |
| 35 | + |
| 36 | +You can copy the default file, and have to update it. Or create your own. |
| 37 | +``` |
| 38 | +cp .env.default .env |
| 39 | +``` |
| 40 | + |
| 41 | +Set your `DB_PASSWORD` and `DB_ROOT_PASSWORD` (for *dev* environment). |
| 42 | + |
| 43 | +## Commands |
| 44 | + |
| 45 | +### Dev |
| 46 | + |
| 47 | +#### First time |
| 48 | +``` |
| 49 | +./bin/dev-start.sh |
| 50 | +``` |
| 51 | +It will starts 2 containers: |
| 52 | +- MariaDB server for the API data on `3306` port. |
| 53 | +- Adminer to manage MariaDB data while programming on http://localhost:8080. |
| 54 | + |
| 55 | +#### Start the app |
| 56 | +``` |
| 57 | +npm run start |
| 58 | +
|
| 59 | +# Watch for changes for automatic restart |
| 60 | +npm run start:watch |
| 61 | +``` |
| 62 | + |
| 63 | +The default URL is http://localhost:3000. |
| 64 | + |
| 65 | +#### Clear all dev data and containers: |
| 66 | +``` |
| 67 | +./bin/dev-clear.sh |
| 68 | +``` |
| 69 | + |
| 70 | +### Prod |
| 71 | +``` |
| 72 | +# Build for production |
| 73 | +npm run prestart:prod |
| 74 | +
|
| 75 | +# Start the production app version |
| 76 | +npm run start:prod |
| 77 | +``` |
| 78 | + |
| 79 | +``` |
| 80 | +# Start all stack |
| 81 | +DB_PASSWORD={{your_pwd}} DB_ROOT_PASSWORD={{your_pwd}} ./bin/prod-start.sh |
| 82 | +``` |
| 83 | + |
| 84 | +``` |
| 85 | +# Inject fixtures |
| 86 | +docker exec rams-prod-app node dist/bin/fixtures-init.js |
| 87 | +``` |
| 88 | + |
| 89 | +``` |
| 90 | +# Clear all prod data and containers |
| 91 | +./bin/prod-clear.sh |
| 92 | +``` |
| 93 | + |
| 94 | +### Data |
| 95 | +``` |
| 96 | +# Insert fixtures data |
| 97 | +npm run fixtures:init |
| 98 | +
|
| 99 | +# Remove all fixtures from DB |
| 100 | +npm run fixtures:clear |
| 101 | +``` |
| 102 | + |
| 103 | +### Tests |
| 104 | +``` |
| 105 | +# Run unit tests |
| 106 | +npm test |
| 107 | +
|
| 108 | +# Run and watch unit tests |
| 109 | +npm run test:watch |
| 110 | +
|
| 111 | +# Run unit tests coverage |
| 112 | +npm run test:coverage |
| 113 | +
|
| 114 | +# Opn coverage html report |
| 115 | +npm run open:coverage |
| 116 | +``` |
| 117 | + |
| 118 | +``` |
| 119 | +# Run end-to-end tests |
| 120 | +npm run e2e |
| 121 | +
|
| 122 | +# Run and watch end-to-end tests |
| 123 | +npm run e2e:watch |
| 124 | +``` |
| 125 | + |
| 126 | +## URLs |
| 127 | + |
| 128 | +- API: http://localhost:3000 |
| 129 | +- Swagger definitions: http://localhost:3000/swagger |
| 130 | +- Adminer: http://localhost:8080 |
| 131 | + |
| 132 | +## TODO |
| 133 | +- Check the compatibility for `enum` in swagger nestjs library ([Github issue](https://github.com/nestjs/swagger/issues/19)). |
| 134 | +- Check the tests coverage for `constructor` with injection |
| 135 | + * [Github issue](https://github.com/istanbuljs/istanbuljs/issues/70) |
| 136 | + * [Angular Issue](https://github.com/angular/angular-cli/issues/5526) |
| 137 | +- Find a way to not expose URLs in Swagger (e.g. list of movies) |
| 138 | + |
| 139 | +## Issues |
| 140 | +- The logger is logging duplication when a request is called. |
| 141 | + |
| 142 | +## Resources |
| 143 | + |
| 144 | +**NestJS** |
| 145 | +- [Documentation](https://docs.nestjs.com/) |
| 146 | +- [Typescript starter](https://github.com/nestjs/typescript-starter) |
| 147 | +- [Examples](https://github.com/nestjs/nest/tree/master/examples) |
| 148 | + |
| 149 | +**Docker** |
| 150 | +- [MySQL container](https://hub.docker.com/_/mysql/) |
| 151 | +- [Adminer container](https://hub.docker.com/_/adminer/) |
| 152 | +- https://github.com/vishnubob/wait-for-it |
| 153 | + |
| 154 | +**Misc** |
| 155 | +- [TypeORM](https://github.com/typeorm/typeorm) |
| 156 | +- TypeScript linter: [TSLint](https://palantir.github.io/tslint/) |
| 157 | +- Watch and reload while coding: [nodemon](https://nodemon.io/) |
| 158 | + |
| 159 | +**Tips** |
| 160 | +- TypeORM repositories for unit testing: [here](https://github.com/nestjs/nest/issues/363#issuecomment-360105413) |
0 commit comments