A Node.js/Express backend API for a brain dump application that allows users to store, manage, and share their content with others. Built with TypeScript, MongoDB, and JWT authentication.
- User Authentication: Sign up and sign in with JWT token-based authentication
- Content Management: Create, retrieve, and delete content with titles and links
- Sharing System: Generate shareable links to share your brain dump with others
- Data Validation: Input validation using Zod schema validation
- TypeScript: Full TypeScript support for better development experience
- MongoDB: NoSQL database for flexible data storage
- Runtime: Node.js
- Framework: Express.js
- Language: TypeScript
- Database: MongoDB with Mongoose ODM
- Authentication: JWT (JSON Web Tokens)
- Validation: Zod
- Environment: dotenv
- Development: Nodemon, ESLint, Prettier
-
Clone the repository
git clone <repository-url> cd brain-dump-backend
-
Install dependencies
npm install
-
Environment Setup Create a
.env
file in the root directory:MONGODB_URI=your_mongodb_connection_string JWT_SECRET=your_jwt_secret_key
-
Build and Run
# Development mode npm run dev # Production mode npm run build npm start
The server will start on http://localhost:3000
http://localhost:3000/api/v1
Create a new user account.
Request Body:
{
"username": "string (3-13 characters)",
"password": "string"
}
Response:
{
"message": "user created successfully"
}
Authenticate user and get JWT token.
Request Body:
{
"username": "string",
"password": "string"
}
Response:
{
"token": "jwt_token_here"
}
Create new content (requires authentication).
Headers:
Authorization: Bearer <jwt_token>
Request Body:
{
"title": "string",
"link": "string"
}
Response:
{
"message": "Content Added"
}
Get all content for authenticated user.
Headers:
Authorization: Bearer <jwt_token>
Response:
{
"content": [
{
"_id": "content_id",
"title": "string",
"link": "string",
"tags": [],
"userId": {
"_id": "user_id",
"username": "string"
},
"createdAt": "date",
"updatedAt": "date"
}
]
}
Create or delete shareable link (requires authentication).
Headers:
Authorization: Bearer <jwt_token>
Request Body:
{
"share": true // true to create, false to delete
}
Response:
{
"createdlink": {
"_id": "link_id",
"hash": "random_hash_string",
"userId": "user_id",
"createdAt": "date",
"updatedAt": "date"
}
}
Get shared content by hash link.
Parameters:
shareLink
: The hash string from the share link
Response:
{
"username": "string",
"content": [
{
"_id": "content_id",
"title": "string",
"link": "string",
"tags": [],
"userId": "user_id",
"createdAt": "date",
"updatedAt": "date"
}
]
}
{
username: String (required, unique),
password: String (required),
createdAt: Date,
updatedAt: Date
}
{
title: String (required),
link: String (required),
tags: [ObjectId] (references Tag model),
userId: ObjectId (required, references User model),
createdAt: Date,
updatedAt: Date
}
{
hash: String,
userId: ObjectId (required, references User model),
createdAt: Date,
updatedAt: Date
}
brain-dump-backend/
βββ src/
β βββ config.ts # Database configuration
β βββ controllers/
β β βββ controllers.ts # API route handlers
β βββ middlewares/
β β βββ middleware.ts # JWT authentication middleware
β βββ models/
β β βββ model.ts # MongoDB schemas
β βββ routes/
β β βββ routes.ts # API route definitions
β βββ utils/
β β βββ random-string-generator.ts # Utility functions
β βββ validators/
β β βββ validators.ts # Zod validation schemas
β βββ index.ts # Server entry point
βββ package.json
βββ tsconfig.json
βββ README.md
npm run build
- Compile TypeScript to JavaScriptnpm start
- Start the production servernpm run dev
- Build and start in development mode with nodemon
- JWT-based authentication
- Input validation using Zod
- Password hashing (implemented in user model)
- Protected routes with middleware
- Environment variable configuration
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the ISC License.