All Projects → CatsMiaow → node-nestjs-structure

CatsMiaow / node-nestjs-structure

Licence: MIT License
Node.js framework NestJS project structure

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to node-nestjs-structure

MyAPI
A template to create awesome APIs easily ⚡️
Stars: ✭ 117 (-54.65%)
Mutual labels:  nest, typeorm, nestjs
nest-boilerplate
Nest.js boilerplate with CircleCI, Commitizen, Commitlint, Docker-Compose, ESLint, GitHub Actions, Husky, Lint-staged, OpenAPI, Prettier, PostGreSQL, Travis CI, TypeORM
Stars: ✭ 16 (-93.8%)
Mutual labels:  nest, typeorm, nestjs
mom
Proof of concept for Message-Oriented-Middleware based architecture.
Stars: ✭ 39 (-84.88%)
Mutual labels:  nest, typeorm, nestjs
Crud
NestJs CRUD for RESTful APIs
Stars: ✭ 2,709 (+950%)
Mutual labels:  nest, typeorm, nestjs
prime-nestjs
A production-ready NestJS boilerplate using Typescript, Postgres, TypeORM, and Docker.
Stars: ✭ 140 (-45.74%)
Mutual labels:  nest, typeorm, nestjs
nestjs-starter
🚀 Nest framework starter
Stars: ✭ 30 (-88.37%)
Mutual labels:  nest, typeorm, nestjs
nestjs-rest-cqrs-example
Example for Nest.js, MySQL, Redis, REST api, CQRS, DDD
Stars: ✭ 263 (+1.94%)
Mutual labels:  nest, typeorm, nestjs
nest-todo
🐱 使用 React.js + Nest.js 实现一个简单的 Todo App。
Stars: ✭ 205 (-20.54%)
Mutual labels:  typeorm, nestjs
Nestjs-Typeorm-Auth
NestJS + Typeorm codebase containing a full authentification system with roles, sessions and email verification.
Stars: ✭ 37 (-85.66%)
Mutual labels:  typeorm, nestjs
axios
Axios module for Nest framework (node.js) 🗂
Stars: ✭ 95 (-63.18%)
Mutual labels:  nest, nestjs
nestlogger
Logger library for NestJs services
Stars: ✭ 28 (-89.15%)
Mutual labels:  nest, nestjs
airbnb-clone
Fullstack airbnb clone made with React/Ts/Nest
Stars: ✭ 37 (-85.66%)
Mutual labels:  nest, typeorm
necord
🤖 A module for creating Discord bots using NestJS, based on Discord.js
Stars: ✭ 77 (-70.16%)
Mutual labels:  nest, nestjs
nest-blog-api
B站全栈之巅:基于TypeScript的NodeJs框架:NestJs开发博客API (node.js+nest.js)
Stars: ✭ 34 (-86.82%)
Mutual labels:  nest, nestjs
Firstsight
前后端分离,服务端渲染的个人博客,基于 Nodejs、 Vue、 Nuxt、Nestjs、PostgreSQL、Apollo
Stars: ✭ 19 (-92.64%)
Mutual labels:  nest, nestjs
mapped-types
Configuration module for Nest framework (node.js) 🐺
Stars: ✭ 192 (-25.58%)
Mutual labels:  nest, nestjs
azure-storage
Azure Storage module for Nest framework (node.js) ☁️
Stars: ✭ 71 (-72.48%)
Mutual labels:  nest, nestjs
nestjs-toolbox
The repository contains a suite of components and modules for Nest.js
Stars: ✭ 166 (-35.66%)
Mutual labels:  nest, nestjs
teanjs
🔥 TypeORM - Express - Angular 8 - NestJS Server Side Rendering (SSR) 😺
Stars: ✭ 62 (-75.97%)
Mutual labels:  typeorm, nestjs
serverless-core-deprecated
[Deprecated] Serverless Core module for Nest framework (node.js) 🦊
Stars: ✭ 169 (-34.5%)
Mutual labels:  nest, nestjs

node-nestjs-structure

Node.js framework NestJS project structure

Started from this issue: nestjs/nest#2249

Configuration

  1. Create a .env file
  2. Edit env config
    • Edit the file in the config folder.
    • default, development, production, test

Installation

# 1. node_modules
npm ci
# 1-1. npm < v7 or Node.js <= v14
npm i
# 2. When import entities from an existing database
npm run entity

If you use multiple databases, modify them.

Development

npm run start:dev

Run http://localhost:3000

Test

npm test # exclude e2e
npm run test:e2e

Production

npm run build
# define environment variable yourself.
# NODE_ENV=production PORT=8000 NO_COLOR=true node dist/app
node dist/app
# OR
npm start

Folders

+-- bin // Custom tasks
+-- dist // Source build
+-- public // Static Files
+-- src
|   +-- config // Environment Configuration
|   +-- entity // TypeORM Entities generated by `typeorm-model-generator` module
|   +-- auth // Authentication
|   +-- common // Global Nest Module
|   |   +-- constants // Constant value and Enum
|   |   +-- controllers // Nest Controllers
|   |   +-- decorators // Nest Decorators
|   |   +-- dto // DTO (Data Transfer Object) Schema, Validation
|   |   +-- filters // Nest Filters
|   |   +-- guards // Nest Guards
|   |   +-- interceptors // Nest Interceptors
|   |   +-- interfaces // TypeScript Interfaces
|   |   +-- middleware // Nest Middleware
|   |   +-- pipes // Nest Pipes
|   |   +-- providers // Nest Providers
|   |   +-- * // models, repositories, services...
|   +-- shared // Shared Nest Modules
|   +-- gql // GraphQL Structure
|   +-- * // Other Nest Modules, non-global, same as common structure above
+-- test // Jest testing
+-- typings // Modules and global type definitions

// Module structure
// Add folders according to module scale. If it's small, you don't need to add folders.
+-- src/greeter
|   +-- * // folders
|   +-- greeter.constant.ts
|   +-- greeter.controller.ts
|   +-- greeter.service.ts
|   +-- greeter.module.ts
|   +-- greeter.*.ts
|   +-- index.ts

Implements

Documentation

# APP, Compodoc
npm run doc #> http://localhost:8080
# API, Swagger - src/swagger.ts
npm run doc:api #> http://localhost:8000/api

File Naming for Class

export class PascalCaseSuffix {} //= pascal-case.suffix.ts
// Except for suffix, PascalCase to hyphen-case
class FooBarNaming {} //= foo-bar.naming.ts
class FooController {} //= foo.controller.ts
class BarQueryDto {} //= bar-query.dto.ts

Interface Naming

// https://stackoverflow.com/questions/541912
// https://stackoverflow.com/questions/2814805
interface User {}
interface CustomeUser extends User {}
interface ThirdCustomeUser extends CustomeUser {}

Index Exporting

# It is recommended to place index.ts in each folder and export.
# Unless it's a special case, it is import from a folder instead of directly from a file.
- import { FooController } from './controllers/foo.controller';
- import { BarController } from './controllers/bar.controller';
+ import { FooController, BarController } from './controllers';
# My preferred method is to place only one fileOrFolder name at the end of the path.
- import { UtilService } from '../common/providers/util.service';
+ import { UtilService } from '../common';

Circular dependency

https://docs.nestjs.com/fundamentals/circular-dependency

# Do not use a path that ends with a dot.
- import { FooService } from '.';
- import { BarService } from '..';
+ import { FooService } from './foo.service';
+ import { BarService } from '../providers';

Variables Naming

refer to Naming cheatsheet

Links

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].