Skip to content

siddheshkothadi/notes-backend

Repository files navigation

Notes - RESTful API using Express and Node

Node.js CI

follow follow

Introduction

Back end for notes web app

This repository contains code for the back end of the notes web app. It is a RESTful server built using Node.js runtime and Express framework, and can perform all the CRUD operations and other database queries on the MongoDB database. I've used MongoDB Atlas as a database and have defined the routes, models using Mongoose.

Getting started

These instructions will help you to set up the server on your local machine for development.

Prerequisites

  1. Node.js - a JavaScript runtime
  2. Git - for cloning and version control
  3. Nodemon - to automatically restart server when file changes in the directory are detected.

Setting up the MongoDB Atlas cluster

  • Follow these instructions to get started with MongoDB Atlas
  • Click on the COLLECTIONS button of your cluster and create two databases inside it :
    1. notes_app
    2. test
  • Inside each database, create two collections named :
    1. notes
    2. users
  • The final structure of your cluster should look something like this :
      Cluster0            // Your main cluster
        |_ notes_app      // Database #1 - Main Database
        |    |_ notes     // (Collection) - All the user notes are saved here
        |    |_ users     // (Collection) - User information is saved here
        |_ test           // Database #2 - For testing
             |_ notes     // (Collection) - Test notes
             |_ users     // (Collection) - Test users
    
  • Finally, click on the CONNECT button of your cluster -> Select Connect your application and note the uri.

    NOTE : Replace <password> with the password for your username. Replace <dbname> with the name of the database, i.e. notes_app for ATLAS_URI and test for ATLAS_TEST_URI.

Generating Google Client Id and Client Secret

  • Follow these instructions to generate the CLIENT_ID and CLIENT_SECRET
  • While generating OAuth Client ID :
    • Add following URIs to Authorized JavaScript origins :
      1. http://localhost:3000
      2. http://localhost:5000
    • Add following URI to Authorized redirect URIs section :
      1. http://localhost:5000/auth/google/callback

Installing

  • Clone this repository using the following command inside the terminal/cmd

    git clone https://github.com/siddheshkothadi/notes-backend
    
    cd notes-backend
    
  • Paste the previously generated ATLAS_URI (by replacing <dbname> with notes_app), ATLAS_TEST_URI (by replacing <dbname> with test), CLIENT_ID and CLIENT_SECRET inside .env file. You can set any value for COOKIE_KEY.

  • Run the folowing command to install the dependencies

    npm install
    

    OR

    yarn
    
  • Finally, run the server

    npm run dev
    

    Hurray! Your server should be running on PORT 5000

  • You've setup the server. Now, you can start the front end for notes web app or you can test GET, POST, PUT, DELETE requests using Postman.

License

This project is licensed under the MIT License - see the LICENSE.md file for details