A REST API Developed with Node.js, Express, and MongoDB for my portofolio website.
This API Is written in JavaScript ES6. which is Very useful in building RESTful web APIs for your front-end platforms like Android, iOS or JavaScript frameworks (Angular, Reactjs, etc).
This project will run on NodeJs using MongoDB as database with Mongoose as the ORM. I am using JWT for handling authentications and JOI for Validating inputs from the user before they are sent to the server and Bcrypt for hashing passwords stored in the database. This Project is open for suggestions, Bug reports and pull requests.
- Basic Authentication (Register/Login with hashed password)
- Email helper ready just import and use.
- JWT Tokens, make requests with a token after login with
auth-tokenheader with valueyourTokenwhereyourTokenwill be returned in Login response as a header value ofauth-token. Role Based Authorizationon Login.- Blog with CRUD operations.
- Comment and Like with in Blog operations.
- Validations added with
JOI. - Included API collection for Postman.
- Test cases with Mocha and Chai.
- configured
.babelto make the code compatible withES6.
- Node.js 8+
- MongoDB 3.6+ (Recommended 4+)
- Clone the project from github.
git clone https://github.com/itisWasp/my-portfolio-API.git- Download repository
- Uncompress to your desired directory
cd myproject
npm install-
Create a new file
.envat the root of your project and configure your environment variables accordingly. -
The file
.envis already ignored in.gitignore, so you never commit your credentials.
├── src
├── app.js
├── index.js
├── controllers
│ ├── Controller.js
│ └── Controller.js
├── models
│ ├── model.js
│ └── model.js
├── routes
│ ├── route.js
│ ├── route.js
│ └── route.js
├── middlewares
│ ├── middleware.js
│ ├── middleware.js
│ ├── middleware.js
├── helpers
│ ├── helpers.js
│ ├── helpers.js
│ ├── helpers.js
│ └── helpers.js
├── test
│ ├── testConfig.js
│ ├── testConfig.js
│ └── testConfig.js
├── package.json
├── package-lock.json npm startYou will know server is running by checking the output of the command npm start
Successfully compiled 20 files with Babel (1232ms).
[nodemon] 2.0.15
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node dist/index.js`
Server Started on Port 5000
Connected to DbNote: we are using nodemon to restart our server in case of any changes in the project.
If you need to add more models to the project just create a new file in /models/ and use them in the controllers.
If you need to add more routes to the project just create a new file in /routes/.
If you need to add more controllers to the project just create a new file in /controllers/ and use them in the routes.
npm testNote: I am using Mocha and Chai to test the endpoints using BDD Unit Testing Approach.
You can configure mocha at package.json file inside scripts property. You can also change timeout for each assertion with --timeout parameter of mocha command.
If you need to add more test cases to the project just create a new file in /test/ and run the command.
Every project needs improvements, Feel free to report any bugs or improvements. Pull requests are always welcome.
This project is open-sourced software licensed under the MIT License. See the LICENSE file for more information.