A backend server for a Smart Point-of-Sale (POS) system, built with Node.js, Express, and PostgreSQL. This server provides RESTful APIs for managing products, inventory, sales, employees, branches, customers, suppliers, and more.
- Features
- Tech Stack
- Project Structure
- Database Schema
- Setup & Installation
- Environment Variables
- API Endpoints
- File Uploads
- Authentication
- Scripts
- License
- User authentication (JWT)
- Role-based access control
- Product, category, inventory, and supplier management
- Employee and branch management
- Customer and sales history tracking
- Cart and order processing
- File/image upload support
- RESTful API design
- Node.js (v18+)
- Express.js
- PostgreSQL
- JWT for authentication
- Multer for file uploads
- dotenv for environment configuration
- CORS support
smart_pos_server/
│
├── config/ # Database and app configuration
│ ├── config.js
│ └── database/
│ ├── schema.sql
│ ├── a_createTables.sql
│ └── ... (other SQL scripts)
│
├── controllers/ # Route controllers
├── middleware/ # Custom middleware (auth, upload)
├── models/ # Database models
├── public/ # Static files and images
├── routes/ # API route definitions
├── utils/ # Utility functions
├── server.js # Main server entry point
├── package.json
└── README.md
- See
config/database/schema.sqlanda_createTables.sqlfor full schema. - Includes tables for products, categories, inventory, sales, employees, branches, customers, suppliers, user roles, and more.
- Uses foreign key constraints for data integrity.
-
Clone the repository:
git clone https://github.com/ChandiH/smart_pos_server.git cd smart_pos_server -
Install dependencies:
npm install
-
Configure environment variables:
- Create a
.envfile in the root directory with the following variables:PORT=4000 DATABASE_USER=your_db_user DATABASE_PASSWORD=your_db_password DATABASE_HOST=localhost DATABASE_PORT=5432 DATABASE_NAME=smart_pos_db SECRET_KEY=your_jwt_secret - Adjust values as needed for your environment.
- Create a
-
Set up the PostgreSQL database:
- Run the SQL scripts in
config/database/to create the database and tables. - Example:
psql -U your_db_user -f config/database/schema.sql psql -U your_db_user -d smart_pos_db -f config/database/a_createTables.sql
- Run the SQL scripts in
-
Start the server:
npm start
- The server will run on the port specified in
.env(default: 4000).
- The server will run on the port specified in
| Variable | Description |
|---|---|
| PORT | Server port |
| DATABASE_USER | PostgreSQL username |
| DATABASE_PASSWORD | PostgreSQL password |
| DATABASE_HOST | Database host (e.g., localhost) |
| DATABASE_PORT | Database port (default: 5432) |
| DATABASE_NAME | Database name |
| SECRET_KEY | JWT secret key |
All endpoints are prefixed by their resource, e.g. /auth, /product, /customer, etc.
POST /auth/login— Login and receive JWT tokenPOST /auth/register— Register a new employeePOST /auth/reset-password— Reset password
GET /product— List productsPOST /product— Add product (supports image upload)GET /inventory— List inventory- ...and more
GET /customer— List customersPOST /customer— Add customerGET /chart— Sales analytics
GET /employee— List employeesPOST /employee— Add employee (supports image upload)GET /branch— List branches
GET /cart— View cartPOST /cart— Add to cartGET /supplier— List suppliers
GET /user-role— List user roles
- Single file:
POST /upload(form field:file) - Multiple files:
POST /upload-multiple(form field:files) - Product images:
POST /product(form field:files) - Employee images:
POST /employee(form field:file) - Uploaded files are stored in
public/image/
- JWT-based authentication.
- Protect routes using the
authJWTmiddleware. - Example usage:
app.use("/customer", jwt.verifyToken, customerRouter);
| Command | Description |
|---|---|
npm start |
Start server |
npm run online |
Start server with nodemon |
npm test |
Run tests (not implemented) |
ISC © Somesh Chandimal
For more details, see the source code and SQL schema files.
If you have any questions or need help, please contact the author or open an issue.