Introduction to using ExpressJS with MongooseJS and NodeJS - Part 2
This is a continuation of my previous blog on using express on NodeJS and MongooseJS. Please refer to that tutorial before continuing further in this tutorial.
Here we gonna continue our previous applications CRUD functionalities, but first we gonna streamline our project by using nodemon package.
Here we gonna continue our previous applications CRUD functionalities, but first we gonna streamline our project by using nodemon package.
- Intializing Nodemon using following command,
- npm install nodemon --save-dev
- Here, Nodemon restarts the server automatically each time you save a file that the server uses.
- The reason for using it as only as a developing dependency is we only need it in development time.
- There are many ways to run the application using nodemon, but i will use a much simpler way,
- Here we gonna define nodemon in run script in package.json
- Now we need to enter the following command in terminal inorder to run the application,
- npm run dev
- So we are back to our main topic CRUD functionalities. We have already created GET-READ capability in previous tutorial.
- Let's start on POST-CREATE capability,
- This POST request can be triggered either with JS or thorugh a <form> element.
- First lest's create a form in index.html which can trigger a POST request.
- On our server, we can handle this POST request with a
post
method that Express provides. It takes the same arguments as the GET method, - Now when nodemon restarts the server,go to localhost:3000 and fill the form and click submit button.
- You will be able to see this output in the terminal.
- Now,we need to get the input values from the form,since Express doesn't handle reading data from form element on it's own, need to add another package called body-parser.
The rest of the tutorial will be updated soon !!! Sorry for the inconvenience ,you can check out the full code Here
Comments
Post a Comment