Skip to content

mutuajoseph/security-masterclass

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

My Users API - Starter Codebase

A simple Node.js Express API for user management. This is the starter codebase that serves as a foundation for implementing various security features and authentication mechanisms.

Project Structure

my-users/
├── controllers/
│   └── userController.js     # Controller functions for user routes
├── middleware/
│   └── errorHandler.js       # Global error handling middleware
├── routes/
│   └── userRoutes.js         # API routes for user endpoints
├── .env                      # Environment variables
├── .gitignore                # Git ignore file
├── app.js                    # Main application entry point
├── package.json              # Project dependencies and scripts
└── README.md                 # Project documentation

Features

  • Express.js web server
  • RESTful API architecture
  • CORS enabled for cross-origin requests
  • Environment variable configuration
  • Basic error handling middleware
  • Request logging

API Endpoints

Method Endpoint Description
GET /api/users Get all users (unsecured)
POST /api/users Create a new user (unsecured)

Prerequisites

  • Node.js (v14 or higher)
  • npm (v6 or higher)

Getting Started

Installation

  1. Clone the repository:

    git clone <repository-url>
    cd my-users
  2. Install dependencies:

    npm install
  3. Create a .env file in the root directory with the following content:

    PORT=3000
    

Running the Application

Development Mode

Run the application with nodemon for automatic restarts during development:

npm run dev

Production Mode

Run the application in production mode:

npm start

The server will start on the port specified in your .env file (default: 3000).

Testing the API

You can test the API using tools like Postman, curl, or any HTTP client.

Example Requests

Get All Users

curl http://localhost:3000/api/users

Expected response:

{
  "message": "Get all users (unsecured)"
}

Create a New User

curl -X POST -H "Content-Type: application/json" http://localhost:3000/api/users

Expected response:

{
  "message": "Create a new user (unsecured)"
}

Next Steps

This starter codebase is designed to be extended with various security features such as:

  1. User authentication with JWT
  2. Password hashing
  3. Rate limiting to prevent brute force attacks
  4. Input validation
  5. Security headers with Helmet
  6. Database integration

License

ISC

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published