Backend for a sample E-Commerce Website developed using NodeJS, Express and MongoDB. Following functionalities are available for use.
- Sign-up a new user
- Login with email and password
- Logout from portal
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.
What things you need to install the software and how to install them.
A step by step series of examples that tell you how to get a development env running.
Install Dependencies
npm install
Create an .env File holding Environment Variables in the Project Root
DATABASE=<Address String of your MongoDB Instance> [Required]
PORT=<Port on which you want your application to run. Default = 8000> [Optional]
SECRET=<Secret for encryption and decryption of Authentication Tokens> [Required]
Run app.js
npm start
Sign Up
Endpoint: /api/signup
Request Type: POST
Body: {
"firstName": "Abc", [Required]
"lastName": "Xyz", [Optional]
"userInfo": "Description", [Optional]
"email": "abc@xyz.com", [Required]
"password": "B#A*jhv8" [Required]
"role": 1 [Optional]
}
Login
Endpoint: /api/login
Request Type: POST
Body: {
"email": "abc@xyz.com", [Required]
"password": "B#A*jhv8" [Required]
}
Logout
Endpoint: /api/logout
Request Type: GET
Get User Details
Endpoint: /api/user/<userId>
Request Type: GET
Header: {
Authorization: Bearer <Token obtained from Login>
}
Update User Details
Endpoint: /api/user/<userId>
Request Type: PUT
Header: {
Authorization: Bearer <Token obtained from Login>
}
Body: {
lastName: "new",
email: "new.email@newmail.org"
}
Get User Purchases
Endpoint: /api/orders/user/<userId>
Request Type: GET
Header: {
Authorization: Bearer <Token obtained from Login>
}
Add additional notes about how to deploy this on a live system.