Global

Members

AddPost

Adds a new post to the database

Source:
Example
// Request body:
{
  "title": "My First Post",
  "content": "This is the content of my post",
  "author": "John Doe"
}

DeleteUser

Deletes a user account after verifying credentials

Source:
Example
// Request body:
{
  "email": "john@example.com",
  "password": "SecurePassword123"
}

GetPosts

Retrieves all posts from the database

Source:
Example
// Success response:
{
  "success": true,
  "result": [
    {
      "_id": "...",
      "title": "Post Title",
      "content": "Post content",
      "author": "Author Name"
    }
  ]
}

(constant) JWT_EXPIRES_IN :string

JWT token expiration time from environment variables

Type:
  • string
Source:

(constant) JWT_SECRET :string

JWT secret key from environment variables

Type:
  • string
Source:

LoginUser

Authenticates a user with email and password

Source:
Example
// Request body:
{
  "email": "john@example.com",
  "password": "SecurePassword123"
}
// Success response:
{
  "success": true,
  "message": "Login successful",
  "user": {
    "username": "johndoe",
    "email": "john@example.com",
    "token": "jwt_token_here"
  }
}

(constant) MAILBOXLAYER_API_KEY :string

Mailboxlayer API key for email verification

Type:
  • string
Source:

(constant) PORT :number

Server port - defaults to 4000 if not specified in environment

Type:
  • number
Source:

RegisterUser

Registers a new user with username, email, and password

Source:
Example
// Request body:
{
  "username": "johndoe",
  "email": "john@example.com",
  "password": "SecurePassword123"
}
// Success response:
{
  "success": true,
  "message": "User registered successfully",
  "user": {
    "id": "...",
    "username": "johndoe",
    "email": "john@example.com"
  }
}

TestConnection

Tests the MongoDB connection and returns the result

Source:
Example
// Request body: {} (empty)
// Success response:
{
  "success": true,
  "result": "Connection successful"
}

(constant) UserSchema :mongoose.Schema

Defines the structure for user documents in MongoDB

Type:
  • mongoose.Schema
Source:

(constant) app :express.Application

Express application instance

Type:
  • express.Application
Source:

(constant) uri :string

MongoDB connection URI from environment variables

Type:
  • string
Source:

Methods

(async) startServer() → {Promise.<void>}

Connects to MongoDB database and starts the Express server. The server will only start if MongoDB connection is successful.

Source:
Throws:

If MongoDB connection fails, the process will exit with code 1

Type
Error
Returns:
Type
Promise.<void>

(async) verifyEmail(email) → {Promise.<Object>|boolean|string}

Verifies if an email address is valid and exists using Mailboxlayer API

Parameters:
Name Type Description
email string

The email address to verify

Source:
Throws:

If API request fails, falls back to allowing the email

Type
Error
Returns:
  • Object containing validation status and reason

    Type
    Promise.<Object>
  • returns.valid - Whether the email is valid

    Type
    boolean
  • returns.reason - Explanation of the validation result

    Type
    string
Example
const result = await verifyEmail('user@example.com');
if (result.valid) {
  console.log('Email is valid:', result.reason);
} else {
  console.log('Email is invalid:', result.reason);
}

Type Definitions

User

Type:
  • Object
Properties:
Name Type Description
username string

User's unique username (min 3 characters)

email string

User's email address (must be valid format)

password string

User's hashed password (min 6 characters)

createdAt Date

Account creation timestamp

Source: