Skip to content

RESTful API from the FIU Project (Backend) developed with TypeScript and the framework Nest.js.

License

Notifications You must be signed in to change notification settings

jamesrhurtado/fixitup-api

 
 

Repository files navigation

Nest Logo

A progressive Node.js framework for building efficient and scalable server-side applications.

NPM Version Package License NPM Downloads CircleCI Coverage Discord Backers on Open Collective Sponsors on Open Collective Support us

Fix it Up Web API with Typescript

Fix it Up Backend Application developed with Typescript and using the framework of Nest. Persistence layer is implemented using TypeORM with MySQL Database. Object Mapping is based on AutoMapper TypeScript. The API has been deployed to IBM Cloud using Cloud Foundry, and uses database services from Amazon Web Services.

Installation

$ npm install

Requisites

Install NestJS

$ npm i -g @nestjs/cli
$ nest --version

Install Dependencies

$ npm i --save typeorm reflect-metadata mysql2
$ npm i --save @nestjs/typeorm @nestjs/cqrs
$ npm i --save typescript-result moment-timezone node-sql-reader
$ npm i @automapper/core @automapper/classes @automapper/nestjs @automapper/types

Install Dev Dependencies

$ npm i --save-dev ts-node @types/node npm-run-all

Scripts at package.json

Add typeorm command under scripts section in package.json

"scripts": {
    ...
    "typeorm": "typeorm-ts-node-commonjs"
}

Create a module

$ nest g resource customers

Environment variables

FIXITUP_DDD_NEST_MYSQL=mysql://{user}:{password}@{host}:{port}/{database}
FIXITUP_DDD_NEST_MYSQL=mysql://root:root@localhost:3306/fixitup-ddd-nest
ENVIRONMENT=local
ENVIRONMENT=prod

Note: Password must be URL encoded, %25 is the url encoding of %.

Fix issue with MySQL 8

Client does not support authentication protocol requested by server; consider upgrading MySQL client. To fix it, run the following command changing the values with your credentials:

ALTER USER '{user}'@'{host}' IDENTIFIED WITH mysql_native_password BY '{password}'
FLUSH PRIVILEGES;

Example:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root'
FLUSH PRIVILEGES;

Migrations

$ npm run typeorm migration:create ./src/common/infrastructure/migrations/InitialSchema
$ npm run typeorm migration:create ./src/common/infrastructure/migrations/MasterData
$ npm run typeorm migration:create ./src/common/infrastructure/migrations/UserEmailUpdate
$ npm run typeorm migration:create ./src/common/infrastructure/migrations/UserEmailReupdate

Running the app

# development
$ npm run start

# watch mode
$ npm run start:dev

# production mode
$ npm run start:prod

Deployment to IBM Cloud Foundry

This backend application has been deployed to IBM Cloud Foundry while using database services from Amazon Web Services.

IBM Cloud

https://cloud.ibm.com/login

Download Cloud Foundry CLI

https://github.com/cloudfoundry/cli/releases

Deployment

$ npm run build
$ cd dist
$ cf push --no-start
- format: cf set-env {app-name} {var-name} {var-value}
$ cf set-env fixitup-ddd-nest ENVIRONMENT prod
$ cf set-env fixitup-ddd-nest FIXITUP_DDD_NEST_MYSQL mysql://{user}:{web service}:3306/fixitup-ddd-nest
$ cf push

Tip - Cloud Foundry Environment Variables

Strings containing the following characters must be quoted:
:, {, }, [, ], ,, &, *, #, ?, |, -, <, >, =, !, %, @, \.

Support

Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please read more here.

License

Nest is MIT licensed.

About

RESTful API from the FIU Project (Backend) developed with TypeScript and the framework Nest.js.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 98.9%
  • Other 1.1%