This project is a demonstration of a REST API for managing a user list, inspired by the Vuestic users list
Based on MVC pattern, the project is organized into the following directories:
.
├── routes/
│ ├── index.js
│ ├── root.js
│ └── users.js
├── controllers/
│ ├── root.js
│ └── users.js
├── models/
│ └── users.js
├── db/
│ └── users.json
├── views/
│ └── index.ejs
├── .editorconfig
├── .env
├── .gitignore
├── app.js
├── package.json
├── README.md
└── vercel.json
This project implements a RESTful API for managing user data. It provides endpoints for creating, reading, updating, and deleting user information. The application is built using Node.js and Express.js, with data stored in a JSON file.
-
Controllers: Handle the logic for processing requests and sending responses.
root.js
: Manages the root route of the application.user.js
: Contains functions for user-related operations (CRUD).
-
Models: Define the data structure and database interactions.
user.js
: Implements functions for reading from and writing to the users JSON file.
-
Routes: Define the API endpoints and map them to controller functions.
index.js
: Main router that combines user and root routes.root.js
: Defines the root route.users.js
: Defines routes for user-related operations.
-
Views: Contains the EJS template for the home page.
index.ejs
: Displays API usage information and examples.
-
app.js: The main application file that sets up the Express server and middleware.
-
vercel.json: Configuration file for deploying the application on Vercel.
GET /users
: Retrieve a list of users with pagination support.GET /users/:id
: Retrieve a single user by ID.POST /users
: Create a new user.PUT /users/:id
: Update an existing user.DELETE /users/:id
: Delete a user.GET /projects
: Retrieve a list of projects with pagination support.GET /projects/:id
: Retrieve a single project by ID.POST /projects
: Create a new project.PUT /projects/:id
: Update an existing project.DELETE /projects/:id
: Delete a project.
More details see in route/
folder
-
Install dependencies:
npm install
-
Start the server:
npm start
For development with auto-restart:
npm run dev
For debugging:
npm run dev-debug
-
The server will start on the port specified in the
PORT
environment variable or default to port 3000. -
To work with the local DB you'll need to use the (Supabase cli)[https://supabase.com/docs/reference/cli/introduction]
This project is configured for deployment on Vercel as temporary solution. The vercel.json
file provides the necessary settings. Current domain is (node-js-demo-rho.vercel.app)[https://node-js-demo-rho.vercel.app/]
PORT
: The port on which the server will run (default: 3000)SUPABASE_URL
: The unique Supabase URL which is supplied when you create a new project in your project dashboard.SUPABASE_KEY
: The unique Supabase Key which is supplied when you create a new project in your project dashboard.
- express: Web application framework
- dotenv: For loading environment variables
- supabase: For running the Supabase stack on your machine
For a complete list of dependencies, refer to the package.json
file.