Documentation

Introduction

Welcome to the NestJS Boilerplate! This document serves as a guide to help you get started with your NestJS projects. NestJS is a powerful and extensible Node.js framework for building scalable and maintainable server-side applications.


Node.js

Node. js is an open-source, cross-platform JavaScript runtime environment and library for running web applications outside the client's browser.


Boilerplate

Welcome to the NestJS Boilerplate! This document serves as a guide to help you get started with your NestJS projects. NestJS is a powerful and extensible Node.js framework for building scalable and maintainable server-side applications.

Prerequisites:

  • Node.js: version 16 or higher
  • nestjs/cli: version 9 or higher
  • Database: PostgreSQL

Installation:

Run the Application:

  • Normal mode: npm run start
  • Watch mode: npm run start:dev

Folder structure:

  • src/
  • | modules/ - Contains individual feature modules, each with its controllers, DTOs (Data Transfer Objects), and services
    • example/
      • dtos/
      • controllers/
      • services/
      • example.module.ts
  • | shared/ - Contains shared resources and utilities.
    • entities/
    • enums/
    • decorators/
    • exceptions/
    • helpers/
    • utilities/
    • interceptors/
  • | config/
  • | main.ts

Features:

  • Authentication - signup/signin/forgot password/reset password
  • SEO module - Seo data like meta title, meta description
  • User module - User crud operation
  • i18n - For multi-langulae
  • S3 utility - For upload files in aws s3 bucket
  • Email utility - For send different emails
  • Error Handling - All exception handling
  • Custom decorators - Custom decorators example
  • Stripe integration - Stripe payment gateway integration

Custom Environment Configuration:

For env files, we are going to use NestJs's inbuilt @nestjs/config module. With the help of this we are able to create multiple env files and also able to validate them when starting the project. So if you missed any variable declaration in any file then it will throw an error.


Code Quality And Code Formatting Checker:

For maintaining standard code quality and code formatting we have added some packages in this project like, Prettier, ESLint and Husky.

1. Prettier

Prettier formats your code in a standard way. We need to set this on the save file event, so everytime you save your file it will automatically format the code for you.

2. ESLint

ESLint is a tool for identifying and reporting on patterns found in ECMAScript/JavaScript code, with the goal of making code more consistent and avoiding bugs.

3. Husky

Husky is a tool that allows us to easily use Git hooks and run the scripts we want at those stages. As an example if we want to make sure that there must be no ESLint error before you commit your code. Then we can achieve that with Husky.


Security:

1. Rate Limit (Throttler)

Rate limiting is used to restrict users to hit an endpoint for a limited amount of time. In other words, by rate limiting, we can control the number of incoming requests per time. As we can define the user can hit an endpoint 10 times every minute. So, if anyone hits that endpoint more than 10 times, then it will throw an error and the user can not access that URL for a limited amount of time.

Advantages of Rate Limit.

  • Rate limiting is mainly used for managing the frequency of incoming requests per duration.
  • Better server load management.
  • Reduced risk of attacks like Brute Force.
  • The server will never be overloaded by incoming API calls.

2. Helmet

Helmet can help protect your app from some well-known web vulnerabilities by setting HTTP headers appropriately. Helmet is a collection of several smaller middleware functions that set security-related HTTP response headers. Some examples include:

helmet.contentSecurityPolicy which sets the Content-Security-Policy header. This helps prevent cross-site scripting attacks among many other things. helmet.hsts which sets the Strict-Transport-Security header. This helps enforce secure (HTTPS) connections to the server. helmet.frameguard which sets the X-Frame-Options header. This provides clickjacking protection. Helmet includes several other middleware functions which you can read about at its documentation website.


Node.js Packages

Welcome to the Node.js Packages

1). oc-npm-node-authentication

A Node.js npm package designed to simplify and enhance user authentication in your applications. This package provides a streamlined set of functions to handle various authentication scenarios:

    Email Authentication:
  • Securely authenticate users based on their email and password.
  • Generate JWT tokens for secure user sessions.
    Mobile Authentication:
  • Authenticate users seamlessly using their mobile number and password.
  • Leverage JWT tokens to ensure secure user sessions.
    Email OTP Authentication:
  • Integrate email verification during the login process using OTPs.
  • Store and verify OTPs securely with TypeORM.
  • Configure JWT tokens for enhanced security.
    OTP Verification:
  • Efficiently verify OTPs entered by users during login.
  • Store OTPs securely with TypeORM.
  • Utilize configurable JWT tokens for robust user sessions.

Refer the package here: https://gitlab.com/oneclickweb/test-npm/-/tree/test?ref_type=heads


2). oc-npm-search-airport

The search-airport package provides a set of functions for managing and searching airport data. It offers tools to reset airport data to a default dump, set custom data dumps, filter airports before searching, and search for airports based on user input and location. These functions return Promise objects, ensuring asynchronous handling. The package utilizes a custom AirportType interface for airport data. Doc for Developers

Refer the package here: https://gitlab.com/ashit_oneclick/search-airport


React.js

React is a free and open-source front-end JavaScript library for building user interfaces based on components. It is maintained by Meta and a community of individual developers and companies.


React.js Boilerplate

Welcome to the React.js Boilerplate


React.js Packages

Welcome to the React.js Packages


HTML

HTML is the standard markup language for creating Web pages. HTML describes the structure of a Web page. HTML consists of a series of elements. HTML elements tell the browser how to display the content.


SEO Checklist Pass Head

Code Example (Select And Copy) :


<!-- SEO Checklist Complated HEAD start -->
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Page Title</title>
<meta name="description" content="Page Description." />
<meta property="og:locale" content="en_US" key="og:locale" />
<meta property="og:type" content="website" key="og:type" />
<meta property="og:title" content="Page Title" key="og:title" />
<meta property="og:description" content="Page Description." key="og:description" />
<meta property="og:url" content="page_url" key="og:url" />
<meta property="og:site_name" content="Baquer" key="og:site_name" />
<meta property="article:publisher" content="page_url" key="article:publisher" />
<meta property="og:image" content="image" key="og:image" />
<meta property="og:image:width" content="1200" key="og:image:width" />
<meta property="og:image:height" content="628" key="og:image:height" />
<meta property="og:image:type" content="image/png" key="og:image:type" />
<meta property="twitter:card" content="summary_large_image" key="twitter:card" />
<meta property="twitter:site" content="@twitter_usernaem" key="twitter:site" />
<meta property="twitter:title" content="Page Title" key="twitter:title" />
<meta property="twitter:description" content="Page Description." key="twitter:description" />
<meta property="twitter:url" content="page_url" key="twitter:url" />
<meta property="twitter:image" content="twitter:image" key="twitter:image" />
<meta name="twitter:label1" content="Est. reading time" key="twitter:label1" />
<meta name="twitter:data1" content="5 minute" key="twitter:data1" />
	
<!-- Add this line for cache  -->
<meta http-equiv="Cache-control" content="public">
	
<link rel='canonical' href="page_url" />
<link rel="apple-touch-icon" sizes="180x180" href="apple_touch_icon_url" />
<link rel="icon" type="image/png" sizes="32x32" href="favicon_32x32_url" />
<link rel="icon" type="image/png" sizes="16x16" href="favicon_16x16_url" />
<link rel="manifest" href="./seo/site.webmanifest" />
<link rel="mask-icon" href="safari_pinned_tab" color="#5bbad5" />
<meta name="msapplication-TileColor" content="#da532c" />
<meta name="theme-color" content="#FCE9F1" />
<!-- SEO Checklist Complated HEAD End -->
	
<!-- Custom CSS Add -->
<link rel="preload" as="style" href="./lib/slick/css/slick.css" importance="high" />
<link defer rel="stylesheet" href="./lib/slick/css/slick.css" onload="this.onload=null;this.rel='stylesheet'" />
			
<link rel="preload" as="style" href="./frontend/assets/style/bootstrap-style.min.css" importance="high" />
<link defer rel="stylesheet" href="./frontend/assets/style/bootstrap-style.min.css" onload="this.onload=null;this.rel='stylesheet'" />
			
<link rel="preload" as="style" href="./frontend/assets/style/style.min.css" importance="high" />
<link defer rel="stylesheet" href="./frontend/assets/style/style.min.css" onload="this.onload=null;this.rel='stylesheet'" />
											

HTML Semantic Elements

Code Example (Select And Copy) :


<header>
	<nav></nav>
</header>
<main>
	<section>
		<article></article>
	</section>
</main>
<aside></aside>
<footer></footer>
											

Avoid using non-semantic elements (e.g., <div>, <span>) when semantic elements (e.g., <header>, <nav>, <main>, <aside>, <artical>, <section>, <footer>) are more suitable.

Button With all attributes

Code Example (Select And Copy) :

<button type="button" id="button_id" class="button_class" name="button_name" aria-label="button_name">BUTTON_VALUE</button>

Output Example :

In this example, we have used the following attributes:

  • type: Specifies the type of button. In this case, it's set to "button", which is the default value.
  • id: Provides a unique identifier for the button, which can be used in JavaScript or CSS.
  • class: Assigns a CSS class to style the button. In this case, it's given the class "btn-primary".
  • name: Specifies the name of the button, often used when the button is part of a form.
  • value: Sets the value that is submitted with the form when the button is clicked. This is commonly used in form submissions.
  • disabled: When set to disabled, the button is not clickable.
  • onclick: Specifies a JavaScript function to execute when the button is clicked. In this example, it displays an alert.

Anchor With all attributes

Code Example (Select And Copy) :

<a href="anchor_tag_link" target="_blank" rel="noopener noreferrer" title="anchor_tag_title" class="anchor_tag_class">ANCHOR_TAG_VALUE</a>

Output Example :

ANCHOR_TAG_VALUE

In this example, we have used the following attributes:

  • href: Specifies the URL the link points to, in this case, "https://example.com".
  • target: Defines how the link will be opened. In this example, it's set to "_blank" to open the link in a new tab or window.
  • rel: Specifies the relationship of the linked document. In this case, it includes "noopener" and "noreferrer" to improve security when opening in a new window.
  • title: Provides additional information about the link, often displayed as a tooltip.
  • download: Suggests that the linked file should be downloaded when clicked. The "example.pdf" is the suggested file name for the download.
  • lang: Specifies the language of the linked document. In this example, it's set to "en" for English.
  • type: Specifies the media type of the linked resource. In this case, it's set to "text/html".
  • class: Assigns a CSS class to style the link. Here, it's given the class "link".
  • style: Allows inline CSS styles to be applied to the link, such as text color and text decoration.

input Text with all attributes

Code Example (Select And Copy) :


<label for="username">Username:</label>
<input type="text" id="username" name="username" value="JohnDoe" placeholder="Enter your username" maxlength="20" size="30" required autocomplete="username" />
													

Output Example :

In this example, we've used the following attributes for the <input> element with type="text":

  • type="text": Specifies the input field as a text input.
  • id: Provides a unique identifier for the input element, which is associated with the label using the for attribute.
  • name: Sets the name of the input field, often used when submitting forms.
  • value: Sets the initial value of the input field to "JohnDoe."
  • placeholder: Provides a hint or example text to the user ("Enter your username").
  • maxlength: Specifies the maximum number of characters that can be entered into the input field (20 characters in this case).
  • size: Specifies the visible width of the input field (30 characters wide in this case).
  • required: Indicates that the field must be filled out before submitting a form.
  • autocomplete: Suggests an autocomplete value for the field (e.g., "username").
  • autofocus: Automatically gives focus to the input field when the page loads.
  • disabled: Disables the input field, making it non-editable.
  • readonly: Makes the input field read-only, meaning the user can't edit it.

input Text with all attributes

Code Example (Select And Copy) :


<label for="email">Email:</label>
<input type="email" id="email" name="email" placeholder="Enter your email" required autocomplete="email">
							

<label for="number">Number:</label>
<input type="number" id="number" name="number" placeholder="Enter a number" min="0" max="100" step="5">
							

<label for="tel">Telephone:</label>
<input type="tel" id="tel" name="tel" placeholder="Enter your phone number" pattern="[0-9]{3}-[0-9]{3}-[0-9]{4}">
							

Output Example :

  • The first <input> uses type="email" to capture email addresses. It includes required and autocomplete attributes.
  • The second <input> uses type="number" to capture numeric input. It specifies min, max, and step attributes to set limits and increment.
  • The third <input> uses type="tel" to capture telephone numbers. It uses a pattern attribute to enforce a specific format (in this case, "xxx-xxx-xxxx").

Image With all attributes

Code Example (Select And Copy) :


				<img src="example.jpg" alt="An example image" aria-label="An example image" width="300" height="200" loading="lazy">
											

Output Example :

An example image

In this example:

  • src: Specifies the image file's source ("example.jpg").
  • alt: Provides alternative text for the image, important for accessibility.
  • width and height: Set the dimensions of the image.
  • loading: Set to "lazy" to enable lazy loading, improving page performance.
  • Add fetchPriority base on your requirement fetchPriority="high | low | auto"

For <picture> :

Use this URL to generate images with responsive breakpoints https://www.responsivebreakpoints.com/ :


<picture>
<source
media="(max-width: 767px)"
sizes="(max-width: 554px) 100vw, 554px"
srcset="
background-image_1_uefngc_ar_1_1,c_fill,g_auto__c_scale,w_320.jpg 320w,
background-image_1_uefngc_ar_1_1,c_fill,g_auto__c_scale,w_554.jpg 554w">
<source
media="(min-width: 768px) and (max-width: 991px)"
sizes="(max-width: 1054px) 70vw, 738px"
srcset="
background-image_1_uefngc_ar_4_3,c_fill,g_auto__c_scale,w_538.jpg 538w,
background-image_1_uefngc_ar_4_3,c_fill,g_auto__c_scale,w_738.jpg 738w">
<source
media="(min-width: 992px) and (max-width: 1199px)"
sizes="(max-width: 1640px) 60vw, 984px"
srcset="
background-image_1_uefngc_ar_16_9,c_fill,g_auto__c_scale,w_596.jpg 596w,
background-image_1_uefngc_ar_16_9,c_fill,g_auto__c_scale,w_984.jpg 984w">
<img
sizes="(max-width: 4780px) 40vw, 1912px"
srcset="
background-image_1_uefngc_c_scale,w_480.jpg 480w,
background-image_1_uefngc_c_scale,w_1912.jpg 1912w"
src="background-image_1_uefngc_c_scale,w_1912.jpg"
alt=""
aria-label="An example image" width="300" height="200" loading="lazy">
</picture>
							
  • The <picture> element is like a container for displaying images on a webpage.
  • Inside the <picture> element, there are different <source> elements, each with a specific condition (like screen width) for when to use them..
  • Depending on the viewer's device and screen size, the browser will choose the most appropriate image from the options provided in the srcset attribute. This helps in optimizing the image for different devices, ensuring it's not too large for small screens or too small for larger screens.
  • The srcset attribute in each <source> element provides a list of different image files and their corresponding widths. It helps the browser choose the most appropriate image to load based on the viewer's device and screen size. This ensures that the right image is displayed for the user's screen, helping to save bandwidth and improve the page's performance.
  • The <img> element is the actual image that will be displayed if none of the <source> conditions match or if the browser doesn't support the <picture> element. The src attribute in the <img> element provides the default image source.
  • Various attributes like alt, width, and height are used for accessibility and layout purposes, while the loading attribute helps improve page load times by loading the image lazily, only when it's about to enter the viewport.

Custom Dropdown using HTML & jQuery

Output Example :

Select an option

Code Example (Select And Copy) :

HTML :


<div class="custom-dropdown">
<div class="selected-option">Select an option</div>
<ul class="dropdown-options">
	<li data-value="option1">Option 1</li>
	<li data-value="option2">Option 2</li>
	<li data-value="option3">Option 3</li>
	<li data-value="option4">Option 4</li>
</ul>
</div>
						

CSS :


.custom-dropdown {
	position: relative;
	width: 200px;
	margin: 20px;
	font-family: Arial, sans-serif;
}
						
.selected-option {
	padding: 10px;
	border: 1px solid #ccc;
	cursor: pointer;
}
						
.dropdown-options {
	list-style: none;
	padding: 0;
	margin: 0;
	display: none;
	position: absolute;
	border: 1px solid #ccc;
	background-color: #fff;
}
						
.dropdown-options li {
	padding: 10px;
	cursor: pointer;
}
						
.dropdown-options li:hover {
	background-color: #f0f0f0;
}
							

Scss :


.custom-dropdown {
	position: relative;
	width: 200px;
	margin: 20px;
	font-family: Arial, sans-serif;
	.selected-option {
		padding: 10px;
		border: 1px solid #ccc;
		cursor: pointer;
	}
	.dropdown-options {
		list-style: none;
		padding: 0;
		margin: 0;
		display: none;
		position: absolute;
		border: 1px solid #ccc;
		background-color: #fff;
		width: 100%;
		li {
		padding: 10px;
		color: #000000;
		cursor: pointer;
		&:hover {
			background-color: #f0f0f0;
		}
		}
	}
	}

jQuery :


$(document).ready(function () {
	// Handle clicking on the selected option to show/hide the dropdown
	$('.selected-option').click(function () {
		$('.dropdown-options').slideToggle();
	});
						
	// Handle selecting an option from the dropdown
	$('.dropdown-options li').click(function () {
		var selectedValue = $(this).attr('data-value');
		$('.selected-option').text($(this).text());
		$('.dropdown-options').slideUp();
	});
						
	// Close the dropdown if the user clicks outside of it
	$(document).click(function (e) {
		if (!$(e.target).closest('.custom-dropdown').length) {
			$('.dropdown-options').slideUp();
		}
	});
});
							

Html Packages

Welcome to the Html Packages


Laravel

Laravel is a free and open-source PHP web framework, created by Taylor Otwell and intended for the development of web applications following the model–view–controller architectural pattern and based on Symfony


Laravel Boilerplate

Welcome to the Laravel Boilerplate


Laravel Packages

Welcome to the Laravel Packages


Support

If this documentation doesn't answer your questions, So, Please contact us.

Note: This is the first version of document, your feedback are most welcome.