NodeJS Introduction – NodeJS 101

 

Overview

In this activity, you create a http server, which will support CRUD operations on Student's data. A file will be used as a persistent storage for the student's data.

PreRequisites

 

Projects you need to complete before trying this project:  JS101

Project Concepts

 

What is nodeJS

Node.js is a platform built on Chrome's JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient.

Node.js apps are developed using Javascript language. Node.js also provides additional JS APIs that can be used the node.js apps.

Node.js is most commonly used to build server applications, though it can also be used to build command-line tools as well as desktop UI applications (using node-webkit).

File Persistence in nodeJS

In this project, you will use the fs module provided by node.js to maintain a file storing student's data (student's id, firstName, lastName, gender and totalMarks). . You will also need to be able to read, update and delete a specific student.

You can enhance the student's FilePersistence module from javascript-async module 

Make http requests to your http server, to perform operation on the Students data.

Sample http server to handle student's data.

In the above example, I have stored student's data in memory object. It perishes once the server is brought down. In place of that, you can use the FilePersistence module developed in javascript-async lesson.

Sample code below..
 

var students = require("./FilePersistence.js")
// You can import your other js files using this notation

//To create a student object upon receiving POST request


//Parse the request body and get the student object.

students.createStudent(student, function(err, data) {
if(err) {
//send response as 400 failed..
} else {
//send response as 200 OK
}