Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

🍱 backend with nest (typescript), typeorm, and authentication

License

NotificationsYou must be signed in to change notification settings

msanvarov/nest-rest-typeorm-boilerplate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Nest Logo

A progressiveNode.js framework for building efficient and scalable server-side applications, heavily inspired byAngular.

NPM VersionPackage LicenseGithub Actions

Table of Contents:

  1. Description
  2. Prerequisites
  3. Deployment
  4. Environment Configuration
  5. Choosing a Web Framework
  6. HTTP2
  7. Choosing a Database
  8. Testing
  9. TypeDocs
  10. Logs

🔎 This repo was created withNx.

📚 Description

This boilerplate is made to quickly prototype backend applications. It comes with authentication/authorization, logging, crud features and database persistence out of the box.


🛠️ Prerequisites

Non Docker

  • Please make sure to haveNode.js (16+) locally by downloading the Javascript runtime viabrew,choco, orapt-get.

  • Please make sure to have MYSQL locally by deploying a web server stack likeXAMPP. The control panel can then trigger MYSQL to start on localhost. MYSQL can be downloaded standalone viabrew,choco, orapt-get.

Docker 🐳

  • Please make sure to haveDocker Desktop operational to quickly compose the required dependencies. Then follow the docker procedure outlined below.

🚀 Deployment

Manual Deployment without Docker

  • Clone the repo viagit clone https://github.com/msanvarov/nest-rest-typeorm-boilerplate.

  • Download dependencies vianpm i oryarn.

  • Create a.env file via thecp .env.example .env command and replace the existing environment variable placeholders with valid responses.

  • Start the api in development mode by usingnpm run start (the app will be exposed onhttp://localhost:3333; not to conflict with React, Angular, or Vue ports).

Optional deployment of the UI
  • This repo comes with a UI built withAngular - that can be accessed viahttp://localhost:4200.

  • To start the UI, start a new terminal window and runnpm run start --project ui.

Remark: In the docker deployment, the UI is automatically started and served by the API.


Deploying with Docker 🐳

  • Execute the following command in-app directory:
# creates and loads the docker container in detached mode with the required configuration$ docker-compose up -d
  • The following command will download dependencies and execute the web application onhttp://localhost:80 (deployed behind a Nginx reverse proxy).

🔒 Environment Configuration

By default, the application comes with a config module that can read in every environment variable from the.env file.

APP_ENV - the application environment to execute as, either in development or production. Determines the type of logging options to utilize. Options:development orproduction.

WEBTOKEN_ENCRYPTION_KEY - the key to encrypt/decrypt web tokens with. Make sure to generate a random alphanumeric string for this.

WEBTOKEN_EXPIRATION_TIME -the time in seconds when the web token will expire; by default, it's 2400 seconds which is 40 mins.

DB_TYPE - the type ofdatabase connection to use.

DB_USERNAME - username for authenticating against the database.

DB_PASSWORD - password for authenticating against the database, can be left empty if a password is not needed (not safe).

DB_HOST - the endpoint where this database sits (default is localhost but can be set explicitly).

DB_PORT - default ports for different types of database connections.

DB_DATABASE - the actual database name to perform operations on.


🏗 Choosing a Web Framework

This boilerplate comes withFastify out of the box as it offersperformance benefits over Express. But the Express adapter is still accessible on adifferent branch.


💾 Choosing a Database

By defaultMYSQL/MariaDB are the database of choice but TypeORM supports other database types like SQLite, Postgres, MongoDB, and MSSQL. To use anything other than MYSQL/MariaDB, change the configuration in the.env file, and download the corresponding wrapper library, likeSQLite3.

Checkhttps://typeorm.io/ for supported database types.

Remark: For MongoDB, TypeORM is not as feature-rich as Mongoose. Thus, I created a boilerplate forNest and Mongoose.


🦾 HTTP/2

Luckily, Fastify can enable HTTP2 over either HTTPS (h2) or plaintext (h2c) out of the box. This boilerplate makes use of this on thefeat/http2 branch where a self-signed certificate was created for testing this capability. The certificate is located in thecerts folder.For production, please use a valid certificate.

The self signed certificate can be generated via OpenSSL:

$ openssl req -x509 -newkey rsa:4096 -keyout api-key.pem -out api-cert.pem -days 365 -nodes

Remark: Express can be ran with HTTP/2 by employing thespdy library.


✅ Testing

Docker 🐳

# Start the docker container if it's not running$ docker start nest-rest-typeorm-api# unit tests$ dockerexec -it nest-rest-typeorm-api npm runtest

Non-Docker

# execute test$ npm runtest

💡 TypeDocs

The documentation for this boilerplate can be foundon Github pages.

The docs can be generated on-demand, by typingnpm run typedocs:api:start. This will produce adocs/api folder with the required front-end files andstart hosting onlocalhost.

Remark: The docs for the ui are generated on-demand, by typingnpm run typedocs:ui:start. This will produce adocs/ui folder with the required front-end files andstart hosting onlocalhost.

# generate docs for api code$ npm run typedocs:api:start

📝 Open API

Out of the box, the web app comes with Swagger; anopen api specification, that is used to describe RESTful APIs. Nest provides adedicated module to work with it.

The configuration for Swagger can be found at thislocation.


✨ TypeORM

TypeORM is an object-relational mapping that acts as an abstraction layer over operations on databases. Please view thedocumentation for further details.

The configuration for TypeORM can be found in theapp module.


🔊 Logs

This boilerplate comes with a Winston module forextensive logging, the configurations for Winston can be found in theapp module.


🏗️ Progress

BranchesStatus
main
feat/*🚧

👥 Contribution

PRs are appreciated, I fully rely on the passion ❤️ of the OS developers.


License

Nest isMIT licensed.

Author

About

🍱 backend with nest (typescript), typeorm, and authentication

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors4

  •  
  •  
  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp