• Stars
    star
    402
  • Rank 107,380 (Top 3 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created about 5 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Hackathon starter project for NestJS. Includes Prisma, email verification, Passport-JWT authentication, Swagger and more

Nest Hackathon Starter Nest Logo

All Contributors

This project contains boilerplate for creating APIs using Nest, a progressive Node.js framework for building efficient and scalable server-side applications.

It is mostly built to be used as a starting point in hackathons and implements common operations such as sign up, JWT authentication, mail validation, model validation and database access.

You can also look at my Angular Hackathon Starter template that shares the same contract with this API.

Features

  1. PostgreSQL with Prisma

  2. JWT Authentication

  3. Mail Verification

  4. Mail Change

  5. Password Reset

  6. Request Validation

  7. Customizable Mail Templates

  8. Swagger API Documentation

  9. Security Techniques

  10. Logger

Getting Started

Installation

  1. Make sure that you have Node.js(>= 10.13.0, except for v13) installed.
  2. Clone this repository by running git clone https://github.com/ahmetuysal/nest-hackathon-starter.git <YOUR_PROJECT_NAME> or directly create your own GitHub repository using this template.
  3. Move to the appropriate directory: cd <YOUR_PROJECT_NAME>.
  4. Run yarn to install dependencies.

Configuration Files

Prisma Configurations

This template uses Postgres by default. If you want to use another database, follow instructions in the official Nest recipe on Prisma.

If you wish to use another database you will also have to edit the connection string on prisma/.env file accordingly.

Template includes three different environment options by default. Most of the time you will use the local environment when developing and production environment on production. You will need to fill out corresponding environment files in env directory.

DATABASE_HOST=__YOUR_DATABASE_URL__
DATABASE_PORT=5432
DATABASE_USERNAME=__YOUR_USERNAME__
DATABASE_PASSWORD=__YOUR_PASSWORD__
DATABASE_NAME=__YOUR_DATABASE__

JWT Configurations

A secret key is needed in encryption process. Generate a secret key using a service like randomkeygen.

Enter your secret key to config.ts file. You can also the change expiration time, default is 86400 seconds(1 day).

  jwt: {
    secretOrKey: '__JWT_SECRET_KEY__',
    expiresIn: 86400,
  },

NodeMailer✉️ Configurations

A delivery provider is required for sending mails with Nodemailer. I mostly use SendGrid to send mails, however, Nodemailer can work with any service with SMTP transport.

To get a SendGrid API key:

  • Create a free account from https://signup.sendgrid.com/
  • Confirm your account via the activation email and login.
  • Create an API Key with mail sending capability.

Enter your API key and sender credentials to config.ts file. Sender credentials are the sender name and sender mail that will be seen by your users.

mail:
    service: {
      host: 'smtp.sendgrid.net',
      port: 587,
      secure: false,
      user: 'apikey',
      pass: '__SENDGRID_API_KEY__',
    },
    senderCredentials: {
      name: '__SENDER_NAME__',
      email: '__SENDER_EMAIL__',
    },
  },

Mail Template Configurations

Mail templates are highly customizable and heavily depend on configurations. Enter your project's information to config.ts. Urls are used as references in the templates. If your mail verification logic is independent from your front-end application, you can use API's own mail verification endpoint, e.g. http://localhost:3000/auth/verify, as mailVerificationUrl. Otherwise, send a HTTP GET request to verification endpoint with token added as a parameter named token, e.g, http://localhost:3000/auth/verify?token=__VERIFICATION_TOKEN__

 project: {
    name: '__YOUR_PROJECT_NAME__',
    address: '__YOUR_PROJECT_ADDRESS__',
    logoUrl: 'https://__YOUR_PROJECT_LOGO_URL__',
    slogan: 'Made with ❤️ in Istanbul',
    color: '#123456',
    // You can enter as many social links as you want
    socials: [
      ['GitHub', '__Project_GitHub_URL__'],
      ['__Social_Media_1__', '__Social_Media_1_URL__'],
      ['__Social_Media_2__', '__Social_Media_2_URL__'],
    ],
    url: 'http://localhost:4200',
    mailVerificationUrl: 'http://localhost:3000/auth/verify',
    mailChangeUrl: 'http://localhost:3000/auth/change-email',
    resetPasswordUrl: 'http://localhost:4200/reset-password',
    termsOfServiceUrl: 'http://localhost:4200/legal/terms',
  },

Migrations

Please refer to the official Prisma Migrate Guide to get more info about Prisma migrations.

# generate migration for local environment
$ yarn migrate:dev:create
# run migrations in local environment
$ yarn migrate:dev

# deploy migration to prod environment
$ yarn migrate:deploy:prod

Running the app

# development mode
$ yarn start:dev

# production
$ yarn build
$ yarn start:prod

Running the tests

# unit tests
$ yarn test

# e2e tests
$ yarn test:e2e

# test coverage
$ yarn test:cov

Contributors

Thanks goes to these wonderful people (emoji key):


Ahmet Uysal

💻 📖 ⚠️

Dimitrios Lytras

💻

This project follows the all-contributors specification. Contributions of any kind welcome!

Support Nest

Nest is an MIT-licensed open source project. If you'd like to join support Nest, please read more here.

License

Licenced under MIT License. Nest is also MIT licensed.

More Repositories

1

angular-hackathon-starter

Hackathon starter project for Angular. Includes generic login/signup pages, navbar, footer, jwt auth and more
TypeScript
23
star
2

KU-LaTeX-Beamer-Template

Unofficial Koç University LaTeX Beamer presentation template.
TeX
6
star
3

hashgraph

Sample implementation of Hashgraph protocol in Go.
Go
5
star
4

karma-mobile

Gamification Hackathon 2019 - Team Karma - Mobile Application Repository
TypeScript
3
star
5

UltimateMonopoly

Comp 302 Term Project for Team Pennybags
Java
3
star
6

SociBoard-Android

Turkish Airlines Travel Hackathon mobile application of team SociBoard. Ranked 3rd. Some parts prototyped with images from design due to limited lime.
Java
2
star
7

ELEC-204

ELEC 204 Digital Design Course Projects
VHDL
2
star
8

UltimateMonopoly-Network

Comp 302 Term Project for Team Pennybags (Server Side)
Java
2
star
9

todo-list

TypeScript
2
star
10

Hash-Code-2018

Our solution for Online Qualification Round of Hash Code 2018 Score: 48,623,204
Java
2
star
11

COMP-416

Java
2
star
12

slidev-presentations

Vue
1
star
13

COMP-304

C
1
star
14

algorithm-practice

Java
1
star
15

COMP-415

TeX
1
star
16

COMP-408

Homework Assignments for Fall 2018 Comp 408 Computer Vision Course of Koç University.
MATLAB
1
star
17

COMP-303

Assembly
1
star
18

basketball-team

Sample GraphQL Spring Boot Application
Java
1
star
19

react-ssr-i18n-material-starter

TypeScript
1
star
20

nest-mixpanel-tracking-proxy

Example NestJS application to proxy tracking requests to Mixpanel's API
JavaScript
1
star
21

Resume

TeX
1
star
22

KT-Hackathon19-Backend

KuveytTürk Hackathon Team Baykuşlar (@ahmetuysal, @mervekarakas) API
C#
1
star
23

LogDos

Simulator implementation for "LogDoS: A Novel logging-based DDoS prevention mechanism in path identifier-Based information centric networks" published in Computers & Security Journal.
Java
1
star
24

KT-Hackathon19-Frontend

KuveytTürk Hackathon-Team Baykuşlar(@ahmetuysal, @mervekarakas)-Frontend
TypeScript
1
star