Skip to content

yogiex/nest-inventory

Repository files navigation

Nest Logo

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

Installation

$ npm install

Running the app

# development
$ npm run start

# watch mode
$ npm run start:dev

# production mode
$ npm run start:prod

Install package untuk database postgres

npm i @nestjs/typeorm typeorm pg @nestjs/config

Konfigurasi app.module.ts database

TypeOrmModule.forRoot({
              type: 'postgres',
              host: process.env.DATABASE_HOST,
              port: parseInt(process.env.DATABASE_PORT),
              username: process.env.DATABASE_USER,
              password: process.env.DATABASE_PASSWORD,
              database: process.env.DATABASE_DB,
              entities: [
                User
              ],
              synchronize: true,
            })

Install package enkripsi

npm i bcrypt
npm i -D @types/bcrypt

Install package untuk dokumentasi Rest API

npm install --save @nestjs/swagger swagger-ui-express

Installasi package untuk jwt

npm i @nestjs/passport @nestjs/jwt passport passport-jwt
npm i -D @types/passport-jwt

Generate JWT KEY

  1. Buka terminal atau command prompt
  2. Copy paste command yang ada dibawah ini untuk generate key dari library crypto
node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"

Generate resource

  1. Generate module
nest g mo auth
  1. Generate service
nest g se auth
  1. Generate controller
nest g c auth

File upload

npm i -D @types/multer

Add logging

npm install winston
  1. lalu buat file logger.ts pada root src
import * as winston from 'winston'
const logger = winston.createLogger({
    format: winston.format.combine(
        winston.format.timestamp(),
        winston.format.json()
    ),
    transports: [
        new winston.transports.Console(),
        new winston.transports.File({filename: 'logs/app.log'})
    ]
})

export default logger;
  1. Import pada file controller lalu letakkan pada setiap controller
import Logger from './logger'

Test

# unit tests
$ npm run test

# e2e tests
$ npm run test:e2e

# test coverage
$ npm run test:cov

Table Routes Information

Routes

HTTP Method Endpoint Description Request Body/Params Response
GET / The root index main pages in nestjs apps
GET /user The List of all users
GET /user/{id} The user's information detail

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.

Stay in touch

License

Nest is MIT licensed.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published