Skip to content

snyk-labs/note-taking-app-nodejs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Note Taking App

A full-stack note-taking application built with Node.js, Express, PostgreSQL, and vanilla JavaScript. Features user authentication, CRUD operations for notes, and a modern responsive UI.

This app was generated by Cursor in Agent mode and using Auto for model choice, on August 25, 2025 using the following prompt

Please build me a note taking app in Node.js. Make it allow users to register and to login. Use PostgreSQL (with Docker)

Features

  • User Authentication: Secure registration and login system with JWT tokens
  • Note Management: Create, read, update, and delete notes
  • Responsive Design: Modern UI that works on desktop and mobile devices
  • Real-time Updates: Notes are updated in real-time across the interface
  • Secure: Password hashing with bcrypt and JWT-based authentication
  • Database: PostgreSQL database with proper relationships and constraints
  • MCP Servers: Includes Playwright and GitMCP Express docs for easy agentic coding

Tech Stack

  • Backend: Node.js, Express.js
  • Database: PostgreSQL
  • Authentication: JWT, bcrypt
  • Frontend: Vanilla JavaScript, HTML5, CSS3
  • Containerization: Docker & Docker Compose

Prerequisites

  • Node.js (v14 or higher)
  • Docker and Docker Compose
  • Git

Installation & Setup

1. Clone the repository

git clone <your-repo-url>
cd note-taking-app-nodejs

2. Install dependencies

npm install

3. Start PostgreSQL with Docker

docker-compose up -d

This will start a PostgreSQL container with the following configuration:

  • Database: note_taking_app
  • Username: postgres
  • Password: postgres
  • Port: 5432

4. Start the application

# Development mode with auto-reload
npm run dev

# Production mode
npm start

The application will be available at http://localhost:3000

API Endpoints

Authentication

  • POST /api/register - User registration
  • POST /api/login - User login
  • GET /api/profile - Get user profile (protected)

Notes (All protected endpoints)

  • GET /api/notes - Get all notes for the authenticated user
  • POST /api/notes - Create a new note
  • GET /api/notes/:id - Get a specific note
  • PUT /api/notes/:id - Update a note
  • DELETE /api/notes/:id - Delete a note

Database Schema

Users Table

CREATE TABLE users (
  id SERIAL PRIMARY KEY,
  username VARCHAR(50) UNIQUE NOT NULL,
  email VARCHAR(100) UNIQUE NOT NULL,
  password_hash VARCHAR(255) NOT NULL,
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

Notes Table

CREATE TABLE notes (
  id SERIAL PRIMARY KEY,
  user_id INTEGER REFERENCES users(id) ON DELETE CASCADE,
  title VARCHAR(255) NOT NULL,
  content TEXT,
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

Usage

  1. Register/Login: Create an account or log in with existing credentials
  2. Create Notes: Use the form at the top to create new notes
  3. View Notes: All your notes are displayed in a responsive grid layout
  4. Edit Notes: Click on any note to open the edit modal
  5. Delete Notes: Use the delete button in the edit modal to remove notes

Environment Variables

The application uses the following default configuration (hardcoded for simplicity):

  • Database Host: localhost
  • Database Port: 5432
  • Database Name: note_taking_app
  • Database User: postgres
  • Database Password: postgres
  • JWT Secret: your-super-secret-jwt-key-change-this-in-production
  • Server Port: 3000

Note: In production, these values should be moved to environment variables.

Security Features

  • Password Hashing: Passwords are hashed using bcrypt with salt rounds
  • JWT Authentication: Secure token-based authentication
  • Input Validation: Server-side validation for all inputs
  • SQL Injection Protection: Parameterized queries using pg library
  • CORS: Cross-origin resource sharing enabled for development

Development

Project Structure

note-taking-app-nodejs/
├── server.js              # Main server file
├── package.json           # Dependencies and scripts
├── docker-compose.yml     # PostgreSQL container setup
├── public/                # Frontend files
│   ├── index.html        # Main HTML file
│   ├── styles.css        # CSS styles
│   └── app.js            # Frontend JavaScript
└── README.md             # This file

Available Scripts

  • npm start - Start the production server
  • npm run dev - Start the development server with nodemon

Troubleshooting

Common Issues

  1. Database Connection Error

    • Ensure Docker is running
    • Check if PostgreSQL container is up: docker ps
    • Verify port 5432 is not in use by another service
  2. Port Already in Use

    • Change the port in server.js or kill the process using port 3000
  3. Dependencies Installation Issues

    • Clear npm cache: npm cache clean --force
    • Delete node_modules and package-lock.json, then run npm install

Docker Commands

# View running containers
docker ps

# View logs
docker-compose logs postgres

# Stop containers
docker-compose down

# Remove containers and volumes
docker-compose down -v

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Test thoroughly
  5. Submit a pull request

MCP

You can scan for the security of MCP servers with mcp-scan

uvx mcp-scan .cursor/mcp.json

License

This project is licensed under the MIT License.

Future Enhancements

  • Rich text editor for notes
  • Note categories and tags
  • Search functionality
  • File attachments
  • Note sharing
  • Dark mode theme
  • Mobile app
  • API rate limiting
  • User roles and permissions

About

A reference note taking app in Node.js

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published