Event Driven Programming with NodeJS
Let's understand the event driven programming in NodeJS using sample implementation by creating a RESTful endpoints in NodeJS with the following requirements:
- A sample CRUD application built with with Node.js, Express, and MongoDB.
- The application allows you to browse through a list of meetings, as well as add, update, and delete meetings.
To run the application
Step 1: Open the console and cd to meeting-service directory:
$ npm install
Step 2: Run the node server
$ node server
To Test the REST endpoints in application on console
1. Get all meetings:
curl -i -X GET http://localhost:3000/meetings
2. Get meeting with _id value of 5753cd2d3485cd440deba5da:
curl -i -X GET http://localhost:3000/meetings/5753cd2d3485cd440deba5da
3. Delete meeting with _id value of 5753cd2d3485cd440deba5da:
curl -i -X DELETE http://localhost:3000/meetings/5753cd2d3485cd440deba5da
4. Add a new meeting:
curl -i -X POST -H 'Content-Type: application/json' -d
'{UserID: "usr151",CalendarID: "cal003",StartTime: "12:00:00",
Duration: "1h",StartDate: "06-07-2016",Subject: "Team Meeting for New Features."}'
http://localhost:3000/meetings
5. Modify meeting with _id value of 5753cd2d3485cd440deba5da:
curl -i -X PUT -H 'Content-Type: application/json' -d
'{UserID: "usr151",CalendarID: "cal003"}' http://localhost:3000/meetings/5753cd2d3485cd440deba5da
Note: Change 5753cd2d3485cd440deba5da with your db id
Running Test Cases you can use the following command
$ mocha
If you have any suggestions/queries feel free to reach me out on vinodkumartiwari@outlook.com.