trangiabao1203 / sample-nodejs-structure

This is my sample nodejs structure using express for restfull api project

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Sample Nodejs Structure

Cài đặt

  1. Cài đặt global để cung cấp câu lệnh mặc định trong command line
  • typescipt: Ngôn ngữ lập trình Typescipt
  • ts-node: Trình biên dịch từ typescript sang javascript
  • nodemon: Kiểm tra sự thay đổi của code
$ sudo npm install -g typescript ts-node nodemon

Cách sử dụng:

$ tsc node.ts
  1. Cài đặt trực tiếp trên project
$ npm install typescript ts-node nodemon

Cách sử dụng:

$ ./node_module/typescript/bin/tsc node.ts

Khởi tạo package.json (Cấu hình mặc định)

$ npm init

Khởi tạo tsconfig.json

$ tsc --init
  • Cấu hình
{
  "compilerOptions": {
    "target": "es6",
    "module": "commonjs",
    "outDir": "./dist",
    "rootDir": "./src",
    "strict": true,
    "moduleResolution": "node",
    "esModuleInterop": true
  },
  "include": ["src/**/*"],
  "exclude": ["node_modules", "**/*.spec.ts"]
}

Thư viện căn bản

  • express: framework dành cho Nodejs
  • mongoose: thư viện xử lý CSDL trong mongoDB
  • body-parser: chuyển đổi dữ liệu body sang json (từ express phiên bản 4 trở lên đã hỗ trợ sẵn body-parser)
$ npm install --save express mongoose

Thư viện hỗ trợ

  • @types/express: hỗ trợ cú pháp es6 cho express
  • @types/mongoose: hỗ trợ cú pháp es6 cho mongoose
$ npm install --save-dev @types/express @types/mongoose

About

This is my sample nodejs structure using express for restfull api project


Languages

Language:TypeScript 100.0%