Creating a Blog API, with full CRUD using NodeJS, Express, Mongoose, and MongoDB.

Overview

Blog API

Blog API that uses CRUD to create, login users, delete and update blog posts. https://blog-api12.herokuapp.com/

Installation

Make a new folder on terminal

mkdir BlogAPI

Clone repository

git clone https://github.com/erosnol/Project-2API

Open up Visual Studio Code

code .
npm init -y 

Make sure all dependencies are up-to-date and installed.

"bcrypt": "^5.0.1",
    "dotenv": "^16.0.1",
    "ejs": "^3.1.8",
    "express": "^4.18.1",
    "express-validator": "^6.14.1",
    "helmet": "^5.1.0",
    "jsonwebtoken": "^8.5.1",
    "mongoose": "^6.3.6",
    "morgan": "^1.10.0"

If not, install dependencies using the following commands:

npm i bcryt
npm i dotenv 
npm i express ejs
npm i express-validator 
npm i helmet
npm i jsonwentoken
npm i mongoose
npm i morgan

Names of ENV Variables

MONGO_DB
MY_SECRET_KEY

Running Locally

Check to see if you are in the /BlogAPI folder within the terminal.

pwd 

cd into /BlogAPI folder and run the server with nodemon

cd BlogAPI
nodemon server.js

If you do not have nodemon installed run this on the terminal

npm i nodemon 

Routes

    Endpoints, Parameters, Schema
app.use('/blog', blogRouter)
app.use('/users', usersRouter)
app.use('/auth', authRouter)

auth Router

Auth ('/auth') creates Users and Login 
 - router.post('/') : Checks users email and password with '.isEmail' & '.notEmpty.' It also creates a TOKEN for user profile.

blog Router

router.get('/') - finds all blogs

router.post('/') - creates a blog 

router.get('/') - find blog by id

router.put('/') - updates blog by id

router.delete('/') - deletes blog by id

user Router

router.post('/') - validates username, email, password with express validator. and use SALT and bcrypt to get a hashedpassword. With this, a payload exists and creates a TOKEN.

Schemas

user

 `username: {
        type: String,
        required: true
    },

    email: {
        type: String,
        required: true,
        unique: true
    },

    password: {
        type: String,
        required: true
    },

    age: {
        type: Number
    },

    birthday: {
        type: Date,
        required: true
    },

    created_at: {
        type: Date,
        default: Date.now()
    }`

blog

 `private: {
        type: Boolean,
        required: true
    },

    blog_title: {
        type: String,
        required: true
    },

    blog_content: {
        type: String,
        required: true
    },

    created_at: {
        type: Date,
        default: Date.now()
    },

    created_by: {
        type: String,
        required: true
    }`

License

MIT

You might also like...

Schema validation utilities for h3, using typebox & ajv

h3-typebox JSON schema validation for h3, using typebox & ajv. Install # Using npm npm install h3-typebox # Using yarn yarn install h3-typebox # Usi

Dec 10, 2022

A simple and composable way to validate data in JavaScript (and TypeScript).

A simple and composable way to validate data in JavaScript (and TypeScript).

A simple and composable way to validate data in JavaScript (and TypeScript). Usage • Why? • Principles • Demo • Examples • Documentation Superstruct m

Jan 9, 2023

Codestamp - Stamp and verify your files and contents

A language-agnostic tool for signing and verifying your (codegen'd) files and contents.

Jan 26, 2022

FieldVal - multipurpose validation library. Supports both sync and async validation.

FieldVal-JS The FieldVal-JS library allows you to easily validate data and provide readable and structured error reports. Documentation and Examples D

Sep 24, 2022

jQuery library to validate html forms. compatible with bootstrap v4 and bootstrap v3

jQuery library to validate html forms. compatible with bootstrap v4 and bootstrap v3

jQuery form validation jQuery form validation is a library that helps you to validate your HTML form, it's completable with both Bootstrap 3 and Boots

Jun 10, 2021

The fastest JSON schema Validator. Supports JSON Schema draft-04/06/07/2019-09/2020-12 and JSON Type Definition (RFC8927)

The fastest JSON schema Validator. Supports JSON Schema draft-04/06/07/2019-09/2020-12 and JSON Type Definition (RFC8927)

Ajv JSON schema validator The fastest JSON validator for Node.js and browser. Supports JSON Schema draft-06/07/2019-09/2020-12 (draft-04 is supported

Jan 4, 2023

GUI for editing, visualizing, and manipulating JSON data

GUI for editing, visualizing, and manipulating JSON data

JSON-Splora JSON-Splora is a GUI for editing, visualizing, and manipulating JSON data with jq or JavaScript. Design Built with Electron Editor and out

Dec 25, 2022

ForgJs is a javascript lightweight object validator. Go check the Quick start section and start coding with love

ForgJs is a javascript lightweight object validator. Go check the Quick start section and start coding with love

Hey every one im really happy that this repo reached this many stars 🎉 ,but this repo needs your contibution I started to better document the code th

Dec 21, 2022
:white_check_mark: Easy property validation for JavaScript, Node and Express.

property-validator ✅ Easy property validation for JavaScript, Node and Express Built on top of validator.js, property-validator makes validating reque

Netto Farah 160 Dec 14, 2022
A lightweight NodeJS library for strict mime-type validation on streams

A lightweight NodeJS library for strict mime-type validation on streams. It gets a ReadableStream and decets the mime-type using its Magic number and validates it using the provided allowed and forbidden lists; If it's allowed it will pass it to the created WritableStreams and if it's not it will throw an error.

CEO of Death Star 9 Apr 3, 2022
Email capture page using Notion API

Notion Capture This starter shows how to use the new Notion API with Next.js. You can capture emails that will populate a Notion database. Live Demo •

Bilal 61 Dec 25, 2022
DiscordEmailVerifier - Quickly verify emails on your tokens for completely free using mail.tm's api.

DiscordEmailVerifier Quickly verify emails on your tokens for completely free using mail.tm's api. /* ❗ No, this code doesn't verify the email for you

eric 3 Jun 7, 2022
Reading emails from Gmail provider using Node.js along with Google API

?? Project summary Reading emails from Gmail provider using Node.js along with Google API (study only). ?? Technologies Project was built using Node.j

Jhony Walker 2 Jan 8, 2022
Schema-Inspector is an JSON API sanitisation and validation module.

Schema-Inspector is a powerful tool to sanitize and validate JS objects. It's designed to work both client-side and server-side and to be scalable wit

null 494 Oct 3, 2022
Tag-input - A versetile tag input component built with Vue 3 Composition API

TagInput A versetile tag input component built with Vue 3 Composition API. Please read this article to learn how to build this package step by step an

Mayank 12 Oct 12, 2022
This Login Form made using React hooks , React Js , Css, Json. This form have 3 inputs, it also validate those inputs & it also having length limitations.

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

Yogesh Sharma 0 Jan 3, 2022
A library for validate a string using regular expressions.

Fogex Form Regex Quickly and easily check if the content is valid. Installation npm install fogex or yarn add fogex Usage import fogex from 'fogex';

null 5 May 5, 2022