Skip to content

Naz1804/note-backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Note App - Backend

A RESTful API backend for a note-taking application built with Node.js and Express. Features secure user authentication and authorization using JWT tokens, full CRUD operations for notes, and comprehensive security measures including rate limiting, input sanitization, and Google OAuth integration. Built with PostgreSQL for robust data management.

Table of contents

Features

  • User authentication (JWT)
  • Google OAuth integration
  • Full CRUD operations for notes
  • Search and filter functionality

Tech Stack

  • Node.js
  • Express
  • PostgreSQL (Neon)
  • JWT
  • bcrypt
  • Helmet
  • Cors
  • express-rate-limit
  • sanitize-html
  • validator
  • dotenv

Prerequisites

  • Node.js v16+
  • PostgreSQL database (or Neon account)

Installation

npm install

Environment Variables

DATABASE_URL=
JWT_SECRET=
CLIENT_ID=
CLIENT_SECRET=
CALLBACK_URL=
REDIRECT_URL=
FRONTEND=

Database Setup

1. Create a Neon PostgreSQL Database

  1. Go to Neon and create a free account
  2. Create a new project
  3. Copy your connection string (it should look like: postgresql://user:password@ep-xxx.neon.tech/dbname)
  4. Add the connection string to your .env file:
   DATABASE_URL=your_connection_string_here

2. Initialize Database Tables

Run the setup script to create all necessary tables:

node scripts/setupDatabase.js

This will create the following tables:

  • users - User accounts with authentication data
  • notes - User notes with tags and archive functionality

3. Verify Setup

Check your Neon dashboard to confirm the tables were created successfully. You should see:

  • users table
  • notes table

Your database is now ready to use!

Running the Application

npm start

API Endpoints

Authentication

  • POST /api/auth/register - Create account
  • POST /api/auth/login - Login
  • GET /api/auth/me - Get current user info
  • DELETE /api/auth/me - Delete account
  • PATCH /api/auth/change-password - Change password
  • PATCH /api/auth/setting - User setting
  • GET /api/auth/google - Google Login
  • GET /api/auth/google/callback - Google Callback

Notes

  • GET /api/notes - Get all notes
  • GET /api/notes/archived - Get all archived notes
  • POST /api/notes/create - Create note
  • GET /api/notes/:id - Find note
  • PATCH /api/notes/:id - Update/Edit note
  • DELETE /api/notes/:id - Delete note
  • PATCH /api/notes/:id/archive - Archive note
  • GET /api/notes/search - Search note
  • GET /api/notes/tags - List tags
  • GET /api/notes/tag - Tag filter notes

Security Features

  • JWT authentication
  • Rate limiting
  • Helmet security headers
  • Input sanitization
  • CORS protection
  • Validator
  • Bcrypt

Project Structure

backend/
├── config/
├── controllers/
├── middleware/
├── models/
├── routes/
├── scripts/
└── utils/

Future Improvements

  • Email verification
  • Password reset via email
  • Note sharing

About

Full-stack PERN application (PostgreSQL, Express, React, Node.js) for managing notes with secure authentication, CRUD operations, and tag-based organization.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors