- Node.js is an open-source and cross-platform JavaScript runtime environment.
- Node.js runs the V8 JavaScript engine, the core of Google Chrome.
- A Node.js app is run in a single process, without creating a new thread for every request.
- Node.js has a unique advantage devloper can write the server-side code in addition to the client-side code.
- Node.js is born on 2009.
- The first form of npm is created 2010.
- Check the nodejs installation with version by.
node -v- Check for NodePackageManager (npm) version.
npm -v- start node terminal you can type
> nodeIt will open the Online REPL Terminal
- Read − Reads user's input, parses the input into JavaScript data-structure, and stores in memory.
- Eval − Takes and evaluates the data structure.
- Print − Prints the result.
- Loop − Loops the above command until the user presses ctrl-c twice.
like
$ node
> 1 + 3
4 - Create the first application as Hellow world as. Create folder day1--> go folder by Cd command -> Now type
npm init
it will ask you ceratin detail, either you can provide details or just click on enter. Now you can see the package.json file on the folder.
- Create file Index.js
write
console.log("Hello world")in index.js. - Go to terminal window, go to day1 folderand type
node index
you will get the output in terminal.
Lets move to day two when we will see the function type. its just basic of Java ECMA6 how we will define it.
- Define Objects.
var obj = {name : "satya", phoneNo : 1234567890, email : "Test@gmail.com"}
console.log(obj);
console.log(obj.name);- anonymous method Function which is not having the name is called anonymous function.
var v = function()
{
console.log("this is anonymous function");
}
v();- Arrow function is based on arrow function keys
var v = () => console.log("this is arrow function");
v()- Multi line values Arrow function.
var v = (a , b) =>
{
console.log("addition is :");
console.log(a + b);
};
v(2,3);In NodeJs Global Object, Object which we can be access by any modules.
We do not need to include these objects in our application, rather we can use them directly
// __dirname : it use to check the directive name.
console.log(__dirname)
//__filename : it use to check the file name.
console.log(__filename)
// Console : it view the data in terimnal.
console.log("Satya")
// Require : include any out side module in page.
var requireTest = require("./requiretest");
console.log(requireTest.abc);Creating your own module.
Requiretest.js
// Arrow function is based on arrow function keys/
const name = "Satya Rathore";
var v1 = () => console.log("this is arrow function");
v1();
module.exports.abc = name;Some other global object are
- //buffer
- //module
- //Reports
- //Process