Tuesday, May 30, 2017

node JS


Node.js

  • Node.js is an Open-Source, Cross-Platform JavaScript  for executing JavaScript code Server-Side.
  • Node.js is primarily used to build network programs such as Web servers.
  • Node.js is free
  • The biggest difference between Node.js and PHP is that most functions in PHP block until completion (commands execute only after previous commands have completed), while functions in Node.js are designed to be non-blocking (commands execute in parallel, and use callbacks to signal completion or failure)
  • Node.js File ends with an extension of .js.
The official website for Node.js: https://nodejs.org

How To Install Node.Js Using Localhost?
  1. Download Node.js Zip File from nodejs.org
  2. Go To Your Terminal
  3. Type sudo tar -C /usr/local --strip-components 1 -xJf node-v6.10.3-linux-x64.tar.xz
  4. Then Check it By Typing node --version
What Can Node.js Do?
  • Node.js can create, open, read, write, delete, and close files on the server
  • Node.js can collect form data from User
  • Node.js can access your  Database (add, delete, modify data in your database)

How To Access Node.js Files Using Terminal?
  1. Create Node.js file in any TEXT EDITOR ans SAVE with an extension of .js
  2. Then go to your terminal and go to your folder and start using Node.js just typing node --version
  3. After in next command call your node.js file which you edited in your editor
    • node file_name.js
  4. Then go to your browser and access the localhost address
  5. In there you can see your codind's output.

An Example : sample.js

var http = require('http');

http.
createServer(function (req, res) {
    res.
writeHead(200, {'Content-Type': 'text/html'});
    res.
end('Hello World!');
}).
listen(8080);



Here you are writing a code "Hello World" to print in your browser. After creating this go to terminal and init nodejs and simply type node sample.js and then go to that local host (8080) in your browser. There You can see you output "Hello World".




5 comments:

My First Day with Uki DN Cohort 1

 "Hello WORLD!"