A boilerplate for REST API Development with Node.js, Express, and MongoDB using TypesScript

Overview

node-mongo-boilerplate

A simple boilerplate for NODEJS, EXPRESS and MONGODB REST API development .

Quick Start

  1. Make sure you have node.js v14 + npm v8 or above installed and ts-node installed.

  2. Clone this repo and cd into it using git clone [email protected]:iamsirmike/node-mongo-boilerplate.git && cd node-mongo-boilerplate.

  3. This project requires a MongoDB server. Make sure you have an active MongoDB instance locally (example here) or remote (example here)

  4. Create a file named .env in the base of your folder and add the mongo url from step 3 above like this

.env

MONGO_URL=<url>

Replace <url> with the actual url.

  1. To get the project ready, run npm install.

  2. To run the project:

    • To automatically rerun when you save, run npm run watch
    • To run once, run npm run start
    • To run tests npm run test

Now you are ready to rumble!

Docker

To get this built and running as a docker container, run the following commands. (You need docker installed for this)

docker build . -t node-mongo-boilerplate:latest
docker run -p 6000:6000 -d node-mongo-boilerplate:latest
You might also like...

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

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

Jan 4, 2023

A boilerplate for Node.js web applications

A boilerplate for Node.js web applications

Hackathon Starter Live Demo: https://hackathon-starter.walcony.com Jump to What's new? A boilerplate for Node.js web applications. If you have attende

Dec 28, 2022

DDD/Clean Architecture inspired boilerplate for Node web APIs

Node API boilerplate An opinionated boilerplate for Node web APIs focused on separation of concerns and scalability. Features Multilayer folder struct

Dec 30, 2022

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

Nov 23, 2022

Node.js Auth Boilerplate

 Node.js Auth Boilerplate

Boilerplate Node.js app demonstrating how to add end-to-end authentication & authorization using PassportJs, Express, MongoDb and Permify

Apr 22, 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

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

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.

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

Dec 26, 2022

🚀 A well-structured boilerplate and Starter for Next.js 12+, Tailwind CSS 3, Redux, Redux Thunk, and TypeScript

🚀 A well-structured boilerplate and Starter for Next.js 12+, Tailwind CSS 3, Redux, Redux Thunk, and TypeScript ⚡️ Made with developer experience first ESLint + Prettier + Lint-Staged + VSCode setup

Nov 28, 2022

A default Next.js project with boilerplate packages and configurations. Includes Tailwind, TypeScript (strict), ESLint, Prettier, and Husky.

Yet another Next.js project template This template includes a set of our favorite dev tools scaffolded into a Next.js project. Tools include: TypeScri

Dec 27, 2022
Comments
  • Improvements

    Improvements

    1. The project has a dependency on MongoDB, but does not say so in the readme, specify how to set one up or a link on how to do that.
    2. The project has a dependency on .env but does not specify an example config or how to set one up and where it should be located. I think preferring a structured and lintable file like yaml or toml makes it easy to avoid petty issues.
    3. server.ts:19 the http server is started even if a connection to mongo fails even though mongo is a direct dependency of the server. You can prevent this by using onconnect.
    4. src/controller/userController.ts:18 even though you are await a promise, it is not wrapped inn a try catch which can lead to unpredictable behaviours when the mongo server fails.
    5. Prefer using named status codes rather than just the code, since a named one is self documenting. er. HttpStatus.BadRequest over 400
    6. src/controller/userController.ts:29 sending unsanitized objects from the db can cause a leakage of critical resources like hashed passwords.
    7. src/db/mongo.ts:10 you are not logging the actualy error which will make debugging painful
    8. src/middleware/auth.ts:6, you need to evaluate the legnth on an array before you select an index, otherwise this can crash you application. People can exploit it to DDoS you server.
    9. src/middleware/auth.ts:12 the evaluation of a jwt token on startup or in post application startup is something you want to do to prevent people from forgetting and having a predetermined key used for encryption.
    10. src/models/userModels.ts:34-36 too much redundancy.
    11. src/validators/createUserValidators.ts:9 you might have a bug here.

    Other ancillary Points

    1. add a linter for the whole project
    2. Prefer organize you files around a module rather than functionality. Functionality will alsways change depending on business need. Modules more or less remain, plus models are easier to reason about. A sample orgainition might looke like this
    user/model.ts
    user/controller.ts
    user/validator.ts
    user/routes.ts
    
    1. Have tests close to files. this way it is easy to perceive which files are missing tests and it is easy to add them on. Having a convention around tests also helps. eg. test for user/controller.ts goes in user/controller_test.ts and you can have jest test all files that have _tests.ts at the end of file names.
    opened by bubunyo 0
Owner
Asamoah Michael
⚡️Mobile Engineer ⚡️UI Developer. 🚀 I turn concepts and ideas into softwares. 👨🏾‍💻 I live and write Flutter.
Asamoah Michael
Express typescript boilerplate using @types/node, @types/express

Express framework boilerplate in typescript.

Harris Gurung 3 Sep 21, 2022
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

Black Axe 16 Dec 13, 2022
A boilerplate for building production-ready RESTful APIs using Node.js, Express, and Mongoose

By running a single command, you will get a production-ready Node.js app installed and fully configured on your machine. The app comes with many built-in features, such as authentication using JWT, request validation, unit and integration tests, continuous integration, docker support, API documentation, pagination, etc. For more details, check the features list below.

Hagop Jamkojian 5k Dec 31, 2022
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

Restu Wahyu Saputra 50 Dec 20, 2022
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
Nestjs boilerplate template (mongodb, typeorm, graphql - code first, i18n, global exception handling etc.)

Description City-Library-Demo project for boilerplate. (node version: 16.14.0, npm version: 8.5.2) First Steps Create .env file in root directory. (Th

Mert Kaygusuz 7 Nov 21, 2022
React Native Boilerplate - The Boilerplate contains all the basic packages, common components and, prebuilt code architecture

The Boilerplate contains all the basic packages, common components and, prebuilt code architecture. It will save developer's project setup time.

MindInventory 36 Dec 26, 2022
Solana Boilerplate - Lightweight boilerplate for Solana dapps. Allows quick building and prototyping.

Lightweight boilerplate for Solana dapps. Allows quick building and prototyping. Feel free to contribute or fork this repository. Make it yours! Leave us a ⭐️ if this repo helped you.

null 21 Nov 15, 2022
Apollo Server Express Boilerplate

Boilerplate for graphql and graphql-ws using Apollo Server Express and powered by TypeORM and TypeGraphQL to make your work is quicker and easier.

Arya W Pratama 10 Dec 14, 2022
@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

Code Collabo 2 May 31, 2022