Nodejs


                                                                   



Node.js is open source, completely free, and used by thousands of developers around the world. It is used to develop I/O intensive web applications like video streaming sites, single-page applications, and other web applications.

Features of Node.js
  • Asynchronous and Event Driven
  • Very Fast
  • Single Threaded but Highly Scalable
  • No Buffering 

Where to Use Node.js? 

Following are the areas where Node.js is proving itself as a perfect technology partner. 
  • I/O bound Applications
  • Data Streaming Applications
  • Data Intensive Real-time Applications (DIRT)
  • JSON APIs based Applications
  • Single Page Applications


Node JS code have the following three important keyword..


Import required modules − We use the require directive to load Node.js modules.

Creating server − A server which will listen to client's requests

Read request and return response − The server created in an earlier step will read the HTTP request made by the client which can be a browser or a console and return the response.


  1. Create a custom module which returns the sum and average of any two numbers passed into it. Require the module and run the server by passing 123 and 321 so that the server prints out the sum and average.
           






  1. Create a simple http server and print “Welcome to Uki. I am yourname”  when a request is sent to your server via the port 8000. (Note - Change different port numbers and check)


      



  1. Using the file system module create a new file called ukinode.txt
3.1 Write a paragraph about Uki into that file


3.2 Serve that file to the client (Read File) over your server
                       


3.3 Append another paragraph about Uki and now serve the new file

3.4 Rename the file as ukinodejsexercise1.txt


3.5 Delete the file you created
            
             
4.   Create two html files called head.html which is a web page which says ‘you have got head ‘ and tail.html which is a web page which says ‘you have got tail’ and save them in the same folder as your node.js files. Create a Node.js file that opens the requested file and returns the content to the client. If anything goes wrong, throw a 404 error.
If you have followed the correct steps you should see two different results when opening these two addresses:
http://localhost:8080/head.html - > You have got head
http://localhost:8080/tail.html -> You have got tail
5. Install the package “upper-case” using NPM and create a Node.js file that will convert the output "Uki is the best place to learn programming !" into upper-case letters.


6.  Create an event handler function that will say “I bark when I see strangers !” when a "bark" event is fired.






7. Install “formidable” module using npm and make a web page in Node.js that lets the user upload files to your computer.
7.1 Save that uploaded file into your Documents directory.


8. Using the Nodemailer module create a server and send a mail to info@uki.life with the subject : “Testing my nodemailer module” , text: “This is easy !”
8.1 Now instead of text send a basic html formatted mail.




No comments