Saiddit: A Reddit Clone RESTful API Backend

Using NODE.js, Express.js and MongoDB!


The below are the available routes on this api.



Returns all of the topics available


Return all the articles for a certain topic


Returns all the articles.


If you want to access an individual article you can include the article ID and it will return a single article using the params articleID.


Get all the comments for a individual article


Returns a JSON object with the profile data for the specified user.



Add a new comment to an article. This route requires a JSON body with a comment key and value pair e.g: {"comment": "This is my new comment"}



Increment or Decrement the votes of an article by one. This route requires a vote query of 'up' or 'down' e.g:


Increment or Decrement the votes of a comment by one. This route requires a vote query of 'up' or 'down' e.g:



Deletes a comment if the comment was created by the default user, 'Northcoder'. Currently this is the only user.


As part of creating a reddit clone this RESTful API uses Node JS, Express JS and MongoDB. The project stack is entirely Javascript allowing fantastic levels of continuity between the front-end and the back-end. This then feeds into a React JS front-end hosted at The database has been populated with seed data.


This application was built in Node JS. Express JS provides all the API routes fetching data from the MongoDB database hosted on mLabs. Should you wish the current output could be connected to your own front-end. Using 'fetch' or the Axios package you can make requests for the data this API provides.


Node.js : 8.3.0
Express.js : 4.14.0
Mongoose": 4.7.0
Body-parser: 1.15.2
Cors: 2.8.4


After seeding the database locally it was connected to an Express server. The Express router is then imported to manage the various endpoints. In order to use MongoDB the database is connected to in the server.js file. The index.js loads in the express server from the server.js file with all it's configurations defined. Initially the server.js connected directly to the database but later i added in a config file.

In order to carry data i installed body-parser and used it within the express server app to parse request bodies into json. I added the routes to a file apiRouter.js using the express.Router(). Then i created a controller.js file to manage all the handling of the requests and responses. This includes the management of calls to the MongoDB. I tested all the routes using either Chrome and Postman. I made show all the data responses were consistent in format, normally sending an object with the 'name' of that response as the response object's only key, and the data itself being the value associated with that key. Obviously, there were a few exceptions to this rule. And some routes do not return a specific response to be handled.

Once i had all the routes working as desired and i had added CORS (Cross-origin resource sharing) i connected a front-end. Once i was sure this was working i created a Heroku project and pushed this project. After a few tweaks to the configuration the project was live.

Finally i added this static page you see now using express.static to designate a point of call for static resources.


Heroku has it's own project configuration variables that can be added to a project. I Initially pushed with my local setup and caused a lot of confusion about what process.env it was loading from.

This is a simple example of the setup of a RESTful API.