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.
- Features
- Tech Stack
- Prerequisites
- Installation
- Environment Variables
- Database Setup
- Running the Application
- API Endpoints
- Security Features
- Project Structure
- Future Improvements
- User authentication (JWT)
- Google OAuth integration
- Full CRUD operations for notes
- Search and filter functionality
- Node.js
- Express
- PostgreSQL (Neon)
- JWT
- bcrypt
- Helmet
- Cors
- express-rate-limit
- sanitize-html
- validator
- dotenv
- Node.js v16+
- PostgreSQL database (or Neon account)
npm installDATABASE_URL=
JWT_SECRET=
CLIENT_ID=
CLIENT_SECRET=
CALLBACK_URL=
REDIRECT_URL=
FRONTEND=
- Go to Neon and create a free account
- Create a new project
- Copy your connection string (it should look like:
postgresql://user:password@ep-xxx.neon.tech/dbname) - Add the connection string to your
.envfile:
DATABASE_URL=your_connection_string_here
Run the setup script to create all necessary tables:
node scripts/setupDatabase.jsThis will create the following tables:
users- User accounts with authentication datanotes- User notes with tags and archive functionality
Check your Neon dashboard to confirm the tables were created successfully. You should see:
- ✅
userstable - ✅
notestable
Your database is now ready to use!
npm start- 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
- 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
- JWT authentication
- Rate limiting
- Helmet security headers
- Input sanitization
- CORS protection
- Validator
- Bcrypt
backend/
├── config/
├── controllers/
├── middleware/
├── models/
├── routes/
├── scripts/
└── utils/
- Email verification
- Password reset via email
- Note sharing