Node.js Video Tutorial List

Stay subscribed. We will keep updating this page whenever we have a new video tutorial on nodejs

nodejs Getting Started: Node.js

..stay subscribed. These email subscriptions are free

Enter your email address:

Node.js Free Video Tutorials

  1. Getting Started: Node.js
  2. callback methods / anonymous functions: jQuery
  3. HTTP Server(request/response): Node.js
  4. HTTP Server(request/response) Counter Application: Node.js
  5. User Input Using readline Module: Node.js
  6. Local Module: Node.js
  7. External Module( NPM ) Install, Update, Remove: Node.js
  8. Network I/O Is Unpredictable: Node.js
  9. URL Redirection Using Node.js
  10. Read Evaluate Print Loop (RELP): Node.js
  11. Adding Routes to Your Server: Node.js
  12. Create/Read/Write File using File Server: Node.js
  13. Server Up or Down: Node.js
  14. Express Web Framework: Node.js
  15. Auto Restart Server With NoDemon: Node.js
  16. Basics of Jade – Template Engine: Node.js
  17. Loops and Conditions In Jade: Node.js
  18. Mixins in Jade: Node.js
  19. Forms Using Jade: Node.js
  20. Configuration of Express Application: Node.js
  21. Basic Routing Using Express: Node.js
  22. Advanced Routing Using Express: Node.js
  23. Middleware In Express: Node.js
  24. Cookies In Express: Node.js
  25. Sessions In Express: Node.js
  26. Error Handling In Express: Node.js
  27. Validating User Request: Node.js
  28. Connecting To MongoDB Using Mongoose: Node.js
  29. Save data To MongoDB: Node.js
  30. Fetch Data From MongoDB: Node.js
  31. Fetch Individual User Data From MongoDB: Node.js
  32. Update / Edit Data In MongoDB: Node.js
  33. Remove / Delete Data From MongoDB: Node.js

External Module( NPM ) Install, Update, Remove: Node.js

This video tutorial illustrates searching, installing, updating and removing the external, free modules.

External Free Node Modules are listed at npmjs.org and is managed by NPMNode Package Manager.

There are so many amazing modules already written to handle so many sophisticated functionalities, that it becomes easy to use them in our application and build a robust, scalable application quickly.

Command to look at all the external module names and their respective description

1
npm search

It gives a long list of names and descriptions.

To make is look better, you can use GREP(if you’re on Linux or Unix based System)
Search with GREP

1
npm search | grep module_name

npm search followed by pipe symbol, which is followed by any module name.

For Windows users

1
npm search module_name

it gives all the details of available methods, properties and their description.

Installation of Modules

init command

1
npm init

Once you run this command, it prompts you with some optional things, like, name of the project, version, author, licensing etc. Once you’re done with that, it creates package.json file with all the details you provided.

The ‘init’ command in NPM allows us to identify our project and list out any Node Modules it requires.

Now open that package.json file: it looks somewhat like this
package.json file

1
2
3
4
5
6
7
8
9
10
11
12
{
  "name": "app",
  "version": "0.0.0",
  "description": "authentication application",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "repository": "",
  "author": "SATISH B",
  "license": "BSD"
}

You need to open this package.json file using a plain text editor and add your project dependencies i.e., some of the modules you need to install for your project.

In this video tutorial we’re installing 3 external modules:
express
jade
mongoose

package.json file, after editing

1
2
3
4
5
6
7
8
9
10
11
12
13
{
  "name": "app",
  "version": "0.0.0",
  "description": "authentication application",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
 "dependencies": { "express": "2.5.8", "jade": "0.26.1", "mongoose": "2.6.5" },
  "repository": "",
  "author": "SATISH B",
  "license": "BSD"
}

Now you’ve specified all the external modules your project depends on.

Now using install command, we need to install these modules.
installation command

1
npm install

Once this command is executed, it looks through the package.json file and installs all the dependency modules one by one.

External Module Install, Update, Remove via NPM: Node.js


[youtube https://www.youtube.com/watch?v=HRISSD0ic2s]

YouTube Link: https://www.youtube.com/watch?v=HRISSD0ic2s [Watch the Video In Full Screen.]



What is a module?
A module is a self-contained series of one or more javascript files represented by an object.

Update Command

1
npm update

once you run this command, package.json file is parsed and the dependency modules are checked for any updates, if any, it’ll be updated.
If any module is installed with -g (global scope), i.e., the root installation, then while updating or removing them, it may throw some errors, in such case, use sudo keyword:

Update Command

1
sudo npm update -g

This would solve the problem both for updating and deleting external modules.

remove/delete module command

1
npm prune

To remove the unused modules: open package.json file and remove the module names which you want to remove. Save the package.json file and then run above(npm prune) command. This would safely remove the modules you no more intend to use in your project.

List Global module: using command

1
npm -g ls

This lists all the global modules, it’s path and file structure: as shown below:

Example output

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
C:\node\express_example>npm  -g ls
C:\Users\Satish\AppData\Roaming\npm
└─┬ [email protected]
  ├── [email protected]
  ├─┬ [email protected]
  │ └── [email protected]
  ├─┬ [email protected]
  │ ├── [email protected]
  │ ├─┬ [email protected]
  │ │ ├── [email protected]
  │ │ └── [email protected]
  │ ├── [email protected]
  │ ├── [email protected]
  │ └── [email protected]
  ├── [email protected]
  ├── [email protected]
  ├── [email protected]
  ├── [email protected]
  ├── [email protected]
  ├── [email protected]
  ├── [email protected]
  └─┬ [email protected]
    └── [email protected]

Removing/Uninstalling Global modules: using command

1
npm -g rm

This removes all the global modules installed.

Clear cache

1
npm cache clear

After modifiying things from command prompt, if it’s still not working, try clearing the cache.

Note:
To install latest version of the module: you’ll need to write * (asterisk or star) in the place of version number inside package.json file.

Local Module: Node.js

In this video tutorial we shall see how to write and make use of local modules in Node.js application.

In previous video tutorials we’ve seen the procedure for writing and using built-in Node.js modules.
HTTP module.
readline Module.

This is a simple tutorial to demonstrate writing of local module

Local Module File
students.js

1
exports.students = [ 'Satish', 'Kiran', 'Sunitha', 'Jyothi' ];

exports is a global provided by node.js
students is a name given by us; it’s a property name and we assign an array to it which contains some names.

Application File
appStu.js

1
2
3
var students = require('./students');
 
console.log(students.students);

We require the local module students in appStu.js file.
./ (dot followed by a forward slash) specifies that it’s a local module and it need not search for the file in core module or node module collection.

Next, object.property name will print out the entire array present inside the local module file.

Local Module: Node.js


[youtube https://www.youtube.com/watch?v=qh2e_9AmakI]

YouTube Link: https://www.youtube.com/watch?v=qh2e_9AmakI [Watch the Video In Full Screen.]



Note:
One of the main advantages of local modules is, the reusability of code. It also helps in separating specific logic and keeping the code clean.

User Input Using readline Module: Node.js

In this video tutorial we shall see how to gather user input and process it inside our node.js application.

In this application, we’ll be asking the user to enter his/her work experience and based on the user input we’ll do some logical processing and output appropriate result to the user.

readline Module
readline.js

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
var rl = require('readline');
 
var prompts = rl.createInterface(process.stdin, process.stdout);
prompts.question("No of years you've been working in corporate?", 
                  function(experience){
 
 var msg = "";
 
 if( experience < 5 )
  msg = "You're short of "+(5-experience)+" years experience to 
         attend job interview at Apple Inc!";
 else
  msg = "Excellent, you're eligible for the job interview!!";
 
 console.log(msg);
 process.exit();
 
});

readline module is built into node.js to facilitate user input in node applications.

createInterface method is used to create an interface for user input.
createInterface method takes 2 parameters: process.stdin and process.stdout. These are standard input and standard output properties of the current process.

Using the createInterface object, we invoke question method.

question method takes 2 parameters:
First one being the question(something which is to be prompted to the user).
Second parameter is an anonymous function.

Response of the user is passed in as argument to this anonymous function.

Inside this anonymous function, we use some simple conditional logic and display the appropriate message to the user, based on his/her input.

i.e., if the person has less than 5 years of job experience, then he/she is not eligible to the job interview at Apple inc. If the job experience is greater than 5 years, then he/she is eligible!!

Finally, we display the content of msg variable using console.log
and exit from the process.

process.exit() is very important. If we don’t exit the process, the interface keeps reading from the standard input.

User Input Using readline Module: Node.js


[youtube https://www.youtube.com/watch?v=Y1TmesiVtGg]

YouTube Link: https://www.youtube.com/watch?v=Y1TmesiVtGg [Watch the Video In Full Screen.]



Output
node readline.js
No of years you’ve been working in corporate? 3
You’re short of 2 years experience to attend job interview at Apple Inc!

node readline.js
No of years you’ve been working in corporate? 9
Excellent, you’re eligible for the job interview!!

Note:
readline module is built into node.js because this is used most often in node applications.
User input is a crucial thing in any sophisticated application.

HTTP Server(request/response) Counter Application: Node.js

This video tutorial is a rapid application development to illustrate HTTP Server(request/response) using Node.js

In this video, we use HTTP Server(request/response): Node.js code and work on it to develop a simple counter application.

Using this application, we can know how many visits have been made since the last server down time!

For explanation of all the keywords and working, please visit HTTP Server(request/response): Node.js

HTTP Server
count.js

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
 var http = require('http');
 var visits = 0;
 
 http.createServer( function(request, response) {
 
console.log('New Connection');
visits++;
 
response.writeHead(200, { 'Content-Type':'text/plain' } );
response.write('Hello\n');
response.write('We have had '+visits+' visits');
response.end();
 
 }).listen(8080);
 
 console.log('Server Started..');

Here we take a variable called visits and initialize it to 0.
Once there is a new connection request, we increment it’s value by 1.
Since there is also request from favicon, practically, there’ll be 2 requests simultaneously: hence the counter increments by 2 for each new connection request.

using write method, we print the number of visits.

HTTP Server(request/response) Counter Application: Node.js


[youtube https://www.youtube.com/watch?v=yRaMJy5Mot0]

YouTube Link: https://www.youtube.com/watch?v=yRaMJy5Mot0 [Watch the Video In Full Screen.]



Output:
Hello
We have had 3 visits

Note:
Once you stop the server or whenever there is down time in the server, the counter is reinitialized once the server is restarted.

Make use of Database to store the counter value, if you need it inspite of server downtime or restarts.