Skip to content

Repository files navigation

PasteIt Server

A feature-rich pastebin API server built with Node.js, Express, TypeScript, and MongoDB.

Features

  • Create, read, update, and delete pastes
  • User authentication with JWT
  • Public, private, and unlisted pastes
  • Password-protected pastes
  • Syntax highlighting support
  • Paste expiration
  • Tagging system
  • Search functionality
  • User preferences

Tech Stack

  • Runtime: Node.js
  • API Framework: Express
  • Language: TypeScript
  • Database: MongoDB
  • Authentication: JWT (JSON Web Tokens)
  • Testing: Jest, Supertest

Getting Started

Prerequisites

  • Node.js (>= 18.0.0)
  • MongoDB

Installation

  1. Clone the repository:
git clone https://github.com/bullet-ant/pasteit-server.git
cd pasteit-server
  1. Install dependencies:
npm install
  1. Create a .env file in the root directory with the following variables:
PORT=3000
MONGODB_URI=mongodb://localhost:27017/pastes
JWT_SECRET=your_jwt_secret_key
  1. Start the development server:
npm run dev

Building for Production

npm run build
npm start

API Endpoints

Authentication

MethodEndpointDescription
POST/api/auth/registerRegister a new user
POST/api/auth/loginLogin with email and password
GET/api/auth/meGet current user profile
PUT/api/auth/meUpdate user profile

Pastes

MethodEndpointDescription
POST/api/pastesCreate a new paste
GET/api/pastes/recentGet recent public pastes
GET/api/pastes/:shortIdGet a paste by ID
POST/api/pastes/:shortIdAccess a protected paste (with password)
GET/api/pastes/:shortId/rawGet raw paste content
PUT/api/pastes/:shortIdUpdate a paste
DELETE/api/pastes/:shortIdDelete a paste
GET/api/pastes/searchSearch for pastes

Users

MethodEndpointDescription
GET/api/users/:userIdGet user profile
GET/api/users/:userId/pastesGet pastes created by a user

System

MethodEndpointDescription
GET/api/healthHealth check endpoint

Testing

Run the test suite with:

npm test

Project Structure

.
├── src/
│ ├── api/ # Express routes and API handlers
│ ├── mongodb/ # MongoDB connection and data access
│ ├── types.ts # TypeScript type definitions
│ └── index.ts # Application entry point
├── test/ # Test files
└── package.json # Project dependencies and scripts

License

This project is licensed under the ISC License.

About

Express server for PasteIt

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages