GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - luisgcenci/nodejs-starter: A Boilerplate for Node.js web applications backed by MongoDB following MVCS pattern.

BranchesTags
Open more actions menu

Latest commit

 

History

17 Commits
17 Commits

Folders and files

NameName
Last commit message
Last commit date
config
config
 
 
controllers
controllers
 
 
middleware
middleware
 
 
models
models
 
 
routes
routes
 
 
services
services
 
 
.env
.env
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
package-lock.json
package-lock.json
 
 
package.json
package.json
 
 
server.js
server.js
 
 
yarn-error.log
yarn-error.log
 
 
yarn.lock
yarn.lock
 
 

Repository files navigation

NodeJS Backend App - Starter

NodeJS app on express framework backed by a MongoDB database following MVC pattern. Includes User Model with CRUD services, as well signin/signup endpoints. Passwords are encrypted using bcryptjs.

Minimum Dependencies

NodeJS
MongoDB
Yarn

Features

Authentication using Email and Password
Add (signup/signin) / Update / Delete Users

Application Structure

backend
├── config
│   └── database.js
├── controllers
│   └── User.controller.js
├── middleware
│   └── auth.js
├── models
│   └── User.js
├── routes
│   └── User.routes.js
├── server.js
└── services
    └── UserService.js
  • config/ - Mongoose config to connect with MongoDB.
  • controllers/ - Serves the responses.
  • middleware/ - Verifies JWT Token.
  • models/ - Schema definitions for mongoose models.
  • routes/ - Routes for API.
  • server.js - Entry point of application.
  • services/ - Business logic between controllers and models.

Set Up

Clone this repo

https://github.com/luisgcenci/signup-login-nodejs-backend-app.git

Install Dependencies

yarn install

Open .env file and insert mongodb uri and replace TOKEN_KEY with a random string.

TOKEN_KEY is used to create JWT Auth.

MONGO_URI="mongodb+srv://username:[email protected]/?retryWrites=true&w=majority"
TOKEN_KEY="RANDOMSTRING"

How to Run

node server.js

Endpoints

URL: /api/v1/user/signup

Method : POST

Auth required : NO

Data Params (Body)

{
    "username": "username",
    "password": "password"
}

Success Response

Code : 201 OK

Returns JWT Auth Token (application/json)

Content example

{
    "jwt_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiNjJjZjliZThmM2MyYTM0NDdlMjEwMjc3IiwidXNlcm5hbWUiOiJyb290IiwiaWF0IjoxNjU3NzczMDMyLCJleHAiOjE2NTc3ODAyMzJ9.2avOPBKgWKcLYdmjs6z5j8Yr8rgi4GossoFyLC6pEg0"
}

URL: /api/v1/user/signin

Method : POST

Auth required : NO

Data Params (Body)

{
    "username": "username",
    "password": "password"
}

Success Response

Code : 201 OK

Returns JWT Auth Token (Application JSON)

Content example

{
    "jwt_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiNjJjZjliZThmM2MyYTM0NDdlMjEwMjc3IiwidXNlcm5hbWUiOiJyb290IiwiaWF0IjoxNjU3NzczMDMyLCJleHAiOjE2NTc3ODAyMzJ9.2avOPBKgWKcLYdmjs6z5j8Yr8rgi4GossoFyLC6pEg0"
}

URL: /api/v1/user/updateusername

Method : POST

Auth required : NO

Data Params (Body)

{
    "username": "username",
    "password": "password",
    "newUsername": "newUsername"
}

Success Response

Code : 201 OK

Returns user object (application/json)

Content example

{
    "_id": "62cf9be8f3c2a3447e210277",
    "username": "newUsername",
    "password": "$2a$10$Z9XNnzvPA77VnggiEtE9juJvFNXFbVVMtSrhNJTPDfpKLM2jF/keO",
    "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiNjJjZjliZThmM2MyYTM0NDdlMjEwMjc3IiwidXNlcm5hbWUiOiJyb290IiwiaWF0IjoxNjU3NzczMDMyLCJleHAiOjE2NTc3ODAyMzJ9.2avOPBKgWKcLYdmjs6z5j8Yr8rgi4GossoFyLC6pEg0",
    "__v": 0
}

URL: /api/v1/user/updatepassword

Method : POST

Auth required : NO

Data Params (Body)

{
    "username": "username",
    "password": "password",
    "newPassword": "newPassword"
}

Success Response

Code : 201 OK

Returns user object (Application JSON)

Content example

{
    "_id": "62cf9be8f3c2a3447e210277",
    "username": "username",
    "password": "newPasswordHashed",
    "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiNjJjZjliZThmM2MyYTM0NDdlMjEwMjc3IiwidXNlcm5hbWUiOiJyb290IiwiaWF0IjoxNjU3NzczMDMyLCJleHAiOjE2NTc3ODAyMzJ9.2avOPBKgWKcLYdmjs6z5j8Yr8rgi4GossoFyLC6pEg0",
    "__v": 0
}

URL: /api/v1/user/deleteuser

Method : DELETE

Auth required : NO

Data Params (Body)

{
    "username": "username",
    "password": "password"
}

Success Response

Code : 201 OK

Returns the count of users deleted. (Application JSON)

Content example

{
    "deletedCount": 1
}

About

A Boilerplate for Node.js web applications backed by MongoDB following MVCS pattern.

Topics

bcryptjsboilerplateexpressmongodbmongoosemvcsnodejsstarter-kit

Resources

Readme
MIT license
Activity

Stars

2 stars

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.