Node Express Template (NET.ts) - a small template project which help you to speed up the process of building RESTful API

Overview

Node Express Template (NET.ts)

The Node Express Template (NET.ts) is a small template project which help you to speed up the process of building RESTful API.

Inside of this repoistory you will find fully configured and ready to use express based web application for Node.js runtime. It’s built on TypeScript and follows the best top-ranked content on Node.js best practices from https://github.com/goldbergyoni/nodebestpractices repository.

Main features:

  • 🐳 Containerized application
  • 🚄 ExpressJS framework with TypeScript on the board
  • ♻️ Live reload
  • 🏇 minified and optimized code for production build
  • ✏️ Linting via ESLint with Airbnb configuration
  • 🚑 Code Formatter with Prettier
  • 📘 VSCode configuration: Debug, Settings, Tasks and extension for ESLint, Prettier, TypeScript
  • 🚧 Jest for unit testing
  • 🏄 And many more...

Getting started

Install Docker and Docker Compose which are used to maximise the convenience of development on local machine.

When both are installed, build the NET.ts image as follow:

docker-compose build

Run the app:

docker-compose up

Go to:

 http://localhost:8080/api/health

If you see the following response in the browser:

{"status":"OK","data":"2022-02-13T20:05:13.965Z"}

It means that everything work as expected. You may start to develop your business logic. Please scroll down to "How to work with NET.ts" section.

Getting started, standard way (no containerization)

If you want to run NET.ts "standard way" using the npm instead of docker-compose. You are free to do it just keep in mind that I develop the NET.ts project on node version 16. Note: you need to set env variables defined in .env.local file. On mac OS you can use source .env.local and export NODE_ENV PORT API_KEY_TOKEN + other envs from .env.local if any.

Install dependencies:

npm install

Run server in dev mode:

npm run server:dev

How to work with NET.ts

There are few rules that you have to obey to enjoy NET.ts fully.

  1. Enviromment variables - define your envs in .env.local file and provide validation rules for them inside @config/config.ts file.
  2. Structure your solution by components. There is an example user CRUD component that shows how you may build logic for your own componnents.
  3. Define your routung inside api.ts fiile.
  4. Describe your newly created API inside swagger.json file
  5. Do not change code inside the core directory.

Testing

The Jest test suites are run by executing

npm test

To run tests directly insiide of the NET.ts container:

docker-compose run web npm run test

Code linting

npm run lint

or insde of the container

docker-compose run web npm run lint

Fixing problems

Automatically fix linter's problems

npm run lint:fix

or insde of the container

docker-compose run web npm run lint:fix

Logging

import logger from '@core/utils/logger';

logger.error('message'); // level 0
logger.warn('message'); // level 1
logger.info('message'); // level 2
logger.http('message'); // level 3
logger.verbose('message'); // level 4
logger.debug('message'); // level 5

In development mode, log messages of all severity levels will be printed to the console. In production mode, only info, warn, and error logs will be printed to the console.

Note: API request information (request url, response code, timestamp, etc.) are also automatically logged (using morgan).

SwaggerUI

An interactive API documentation of NET.ts can be accessed at the path: /api-docs
For local development use this: http://localhost:8080/api-docs
If your webservice's basePath is different from "/" put basePath after api-docs in url address e.g.
for service placed under subfolder the correct URL is: https:// / /api-docs/
Remember to select correct protocol befor you try to call any endpoint, "http" is used only for local development.
Important: swaggerUI is disabled for the production env

Known issues

You might also like...

About Folder pattern for express rest api starterkit clean architecture, easy to scalable and easy to maintenance.

Express Rest Api Clean Architecture The following is a folder pattern for express rest api starterkit structure pattern that I usually use, so if you

Dec 20, 2022

Webplate is an awesome front-end framework that lets you stay focused on building your site or app all the while remaining really easy to use.

Webplate Framework Webplate is an awesome front-end framework that lets you stay focused on building your site or app all the while remaining really e

Nov 24, 2022

Template repo for any node.js project

App Name The project uses: ESLint для линтинга кода, используется свой styleguide основанный на airbnb стандарте. prettier для форматирования кода. hu

Dec 20, 2021

@code-collabo's node-mongo API boilerplate template (typescript)

@code-collabo's node-mongo API boilerplate template (typescript) This is the manual download option for the API boilerplate template generated by @cod

May 31, 2022

The next small thing in web development, powered by Svelte

sapper The next small thing in web development, powered by Svelte. What is Sapper? Sapper is a framework for building high-performance universal web a

Jan 2, 2023

korrijs is a backend framework that built on express.js

körri-backend this is not a fork of any project. please support. -features: -automatic routing from file system "/routers" directory for eg.: you have

Aug 22, 2022

Very minimalistic boilerplate to start most Typescript Express projects. Includes Mongodb connection via Mongoose with a sample post model.

Very minimalistic boilerplate to start most Typescript Express projects. Includes Mongodb connection via Mongoose with a sample post model.

Minimalist express-typescript-boilerplate Available Scripts - `tsc' - builds the tsc project to the dist folder - `build` - cleans the previous build

Dec 13, 2022

A NodeJS Express server that uses Prisma ORM.

Express - Prisma Template (Typescript) A NodeJS Express server that uses Prisma ORM. Stack NodeJS Express Prisma TypeScript File Structure src/config

Feb 4, 2022

A simple Fast CLI that create Express+Mongoose MVC pattern

express-schema-generator Site | Docs | Contributing | Code of Conduct | Twitter | Chat Bored Writing and Creating the Same Express MVC Folders Again a

Aug 15, 2022
Comments
  • Introduce unique id in every log per request

    Introduce unique id in every log per request

    The first log message should start with the request identifier, such as: web_1 | 2022-08-25 07:07:11 START RequestId: c4d71434-41cc-4295-b4a9-7ee68afe0541 The rest of the log messages should also contains ID, example log for /api/health: web_1 | 2022-08-25 07:07:12 c4d71434-41cc-4295-b4a9-7ee68afe0541 info: GET /api/health 200 - 10.685 ms The last log message for the request should looks like that: web 1 | 2022-08-25 07:07:13 END RequestId: c4d71434-41cc-4295-b4a9-7ee68afe0541

    enhancement 
    opened by przemek-nowicki 1
Owner
Przemek Nowicki
Przemek Nowicki
Hi there! This is a react native starter which used to build a awesome Event Booking App based on the Figma design. You can download or clone it to speed up your projects.

mcrn-event-booking-app-starter Hi there! This is a react native starter which used to build a awesome Event Booking App based on the Figma design. You

Roy Chen 43 Dec 19, 2022
Express typescript boilerplate using @types/node, @types/express

Express framework boilerplate in typescript.

Harris Gurung 3 Sep 21, 2022
This is a template project demonstrating how the MERN stack(Mongo, Express, React, Node) can be used, here we have the back end implementation and there is the React implementation as the front end

Versão em português MERN stack This is a template project demonstrating how the MERN stack(Mongo, Express, React, Node) can be used, here we have the

Douglas Samuel Gonçalves 2 Jan 22, 2022
An upgradable boilerplate for Progressive web applications (PWA) with server side rendering, build with SEO in mind and achieving max page speed and optimized user experience.

React PWA v2 A highly scalable, Progressive Web Application foundation,boilerplate, with the best Developer Experience. Demo: https://demo.reactpwa.co

Atyantik 2.5k Dec 26, 2022
Postgres Node.js Express TypeScript application boilerplate with best practices for API development.

Node TypeScript Boilerplate Postgres Developer Ready: A comprehensive template. Works out of the box for most Node.js projects. This project is intend

Chirag Mehta 9 Aug 28, 2022
A boilerplate for REST API Development with Node.js, Express, and MongoDB using TypesScript

node-mongo-boilerplate A simple boilerplate for NODEJS, EXPRESS and MONGODB REST API development . Quick Start Make sure you have node.js v14 + npm v8

Asamoah Michael 5 Oct 16, 2022
A professional front-end template for building fast, robust, and adaptable web apps or sites.

HTML5 Boilerplate HTML5 Boilerplate is a professional front-end template for building fast, robust, and adaptable web apps or sites. This project is t

H5BP 53.8k Dec 28, 2022
Opinionated SvelteKit Template for building web applications.

Opinionated SvelteKit Template for building web applications.

Manassarn 7 Jan 1, 2023
React Starter Kit — isomorphic web app boilerplate (Node.js, Express, GraphQL, React.js, Babel, PostCSS, Webpack, Browsersync)

React Starter Kit — "isomorphic" web app boilerplate React Starter Kit is an opinionated boilerplate for web development built on top of Node.js, Expr

Kriasoft 21.7k Jan 1, 2023
A boilerplate application for building Node.js back-end application in TypeScript

RESTful API Node Server Boilerplate A boilerplate/starter project for quickly building RESTful APIs and with typescript ?? Installation Install the de

Youssef Hajjari 14 Nov 23, 2022