Let's write Code

I AM A FULL STACK JAVASCRIPT DEVELOPER AND WEB BLOGGER
FOR RUNNING NODE-JS APPLICATION WE REQUIRE :
- We need to have
Node-JSinstalled on our system.Node-JSincludes theNode-JSruntime and NPM
NODE-REPL :
REPL(READ EVALUATE PRINT LOOP)The Node
REPLis a powerful tool for Node.js developers, providing a quick and interactive way to experiment with code.If we write on our terminal
nodeOutput
Welcome to Node.js v18.12.1.Basically it enters into a program , a kind of C++ like program or it's a kind of Node REPL.
Over here in piece of Node-JS code will work.
Example :
2+3 Output : 5 let i = 20 let j = 30 i + j Output : 50 console.log("Kapil") Output: Kapil
We are running java script code on the
Node runtimeenvironment.So
Node-JSis a Java Script run time environment.
EXECUTION OF THE CODE :
Whenever we write any piece of Java Script code
Node-JSpasses the code to the V8 engine then V8 engine executes the code.This whole process is known as Node REPL.
The code which we are running on the terminal is very similar to running the code on the
browser console.For running java script code on VS CODE Terminal write :
node app.js
- Here
app.jsis the name of the file.
GLOBAL OBJECT :
windowis the global object given by the browser.On the browser console
thisalso refers to thewindowobject.In the VS CODE if we write :
console.log(global)
Output :
<ref *1> Object [global] {
global: [Circular *1],
queueMicrotask: [Function: queueMicrotask],
clearImmediate: [Function: clearImmediate],
setImmediate: [Function: setImmediate] {
[Symbol(nodejs.util.promisify.custom)]: [Getter]
},
structuredClone: [Function: structuredClone],
clearInterval: [Function: clearInterval],
clearTimeout: [Function: clearTimeout],
setInterval: [Function: setInterval],
setTimeout: [Function: setTimeout] {
[Symbol(nodejs.util.promisify.custom)]: [Getter]
},
atob: [Function: atob],
btoa: [Function: btoa],
performance: Performance {
nodeTiming: PerformanceNodeTiming {
name: 'node',
entryType: 'node',
startTime: 0,
duration: 54.420299999881536,
nodeStart: 3.643099999986589,
v8Start: 8.012600000016391,
bootstrapComplete: 40.96389999985695,
environment: 26.332500000018626,
loopStart: -1,
loopExit: -1,
idleTime: 0
},
timeOrigin: 1724845640522.583
},
fetch: [AsyncFunction: fetch]
}
globalis not a part of our V8 engine. It is one of the superpower which is given to us byNode-JS.globalobject gives us access to many features example :setTimeout,setIntervaland many others.In VS Code if we write
console.log(this) Output: {} //It represents an empty object
- In browser console if we type
thisit points us to thewindowobject.
globalThis :
globalThisis referring to global this across all java script runtime.In VS Code if we write
console.log(globalThis)
Output :
similar to console.log(global)
- In other words
globalThisand this represent samethis. So if we write :
console.log(globalThis === global)
Output :
true



