Git Product home page Git Product logo

base-nestjs-api's Introduction

Base NestJS API

This project is a skeleton for a generic NestJS API with an user table, authentication and role based authorization, and was created to be used as a startup for backend projects.

Features

  • User creation
  • Authentication (with username/password)
  • User listing with role based authorization

There are some decorators that can be used on new endpoints, like UseGuards for endpoints that needs authentication, and the Roles that can be used in conjunction with UseGuards to implement role based authorization

Libraries

Authentication: @nestjs/jwt, @nestjs/passport, passport, passport-jwt, passport-local

Encryption: bcrypt

ORM: Prisma

Utilities: class-transformers, class-validator

Installation

After cloning the repo, enter his folder using:

  cd base-nestjs-api

Install the dependencies using

  npm install
  
  yarn install

Setup the .env file at the root folder. It should be something similar to this:

DATABASE_URL="postgresql://postgres:root@localhost:5432/database?schema=public"
SALT_ROUNDS=10
JWT_SECRET=12345678910
JWT_EXPIRE=3600s

Apply the migration to the database by running the migrate:deploy script:

npm run migrate:deploy

yarn migrate:deploy

Now you can run the application by executing:

npm run dev

yarn dev

And the application will be running on your 3000 port.

API Documentation

Create an user

  POST /users
Parameter Type Description
email string Mandatory. The user's email used to sign in
password string Mandatory. The user's password
firstName string Mandatory. The user's first name
lastName string Mandatory. The user's last name

Authenticate with email and password

  POST /authenticate/password
Parameter Type Description
email string Mandatory. The user's email
password string Mandatory. The user's password

List all the users (only for admin users)

  GET /users

Authors

base-nestjs-api's People

Contributors

thiscosta avatar

Stargazers

Bruno Nakahara avatar  avatar

Watchers

James Cloos avatar  avatar

Forkers

fabiomts

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.