

Inside this folder called api, create three separate folders called models, routes, and controllers by running mkdir api/controllers api/models api/routesĬreate todoListController.js in the api/controller folder, todoListRoutes.js in the routes folder, and todoListModel in the model folder - touch api/controllers/todoListController.js api/models/todoListModel.js api/routes/todoListRoutes.js In this server, we will writing the protocols to create our server. Having done all these, your folder structure should look like this:Ĭreate a file called server.js - touch server.js. Kindly type yes and press enter to complete the creation of our package.json. You should have something like this eventually. Npm init will prompt you to enter some information such as the app name, description, version, author, keyword and also ask if what you see is what you like.

Package.json is a file that gives the necessary information to npm which allows it to identify the project as well as handle the project's dependencies. Navigate to the root of your newly created folder - cd todoListApi Open your terminal and kindly follow the following stepsĬreate a Folder name todoListApi - mkdir todoListApi If you do have Node and MongoDB installed, let's begin the tutorial with the following basic steps.
Nodejs rest api how to#
If you don’t have it installed, kindly go through this link on how to install it in order for us to create a server in Node and Mongodb. Kindly run npm -v and mongo -version as these will show you the version of NPM and MongoDB installed on your machine. I presume that you already have your environment set up (i.e Node.js and MongoDB is installed).
Nodejs rest api update#
endpoints that will create a task, get or read list of all tasks, read a particular task, delete a task, and update a task). To achieve this, we will create a RESTful todo list API (i.e.

The REST architectural style describes six constraints that were originally communicated by Roy Fielding in his doctoral dissertation and defines the basis of RESTful-style as: It is web standards architecture and HTTP Protocol. REST is an acronym for Representational State Transfer.
