Introduction to NodeJs Flashcards
What is NodeJs??
NodeJs is a javascript runtime built on google’s open-source V8 javascript engine.
REPL
Read-Eval-Print-Loop
it is an environment like the browser console, where we can write Js code .
We acces the REPL by taping node in the terminal
By hitting tab twice, you can see all the global variables that are available in Node.
NodeJs supports ES6 in all the newer versions out of the box without any problem.
💡 _ : previous result
Run a file in nodeJs
All we do is to use our node command :
node + the name of the file you want to execute in the terminal
$ node index.html
Modules in NodeJS
Node JS is build around the concept of modules where all kinds of additional functionality are stored in a module.
To use module :
-we do require them into our code.
-and then store the result of requiring function in a variable.
💡 The result is an object
JAVASCRIPT OUTSIDE THE BROWSER
Every browser natively understand html, css and Javascript, no matter you use vanilla js or js framework.
In this case the browser is then the javascript runtime.
what if we could take JavaScript out of the browser and simply execute or JavaScript code somewhere else without all the restrictions that we have in the browser?
NodeJs is the solution that allows us to executed JS outside of the browser.It’s just another JS runtine.
It’s just like a container, like an environment, in which a program written in JS can be executed.
who actually does execute the code if not the browser?
that’s where the V8 engine developed by Google comes into place.
that is exactly where JavaScript code will be parsed and run(executed) in NodeJS.
JAVASCRIPT ON THE SERVER
Now that we have JS outside the browser, we can do so many good things that were completely impossible before, like aceessing the file system and networking capabilities without nodeJS.
All these factors give us the perfect conditions for using nodeJS as a web server.
We can now use JS on the server-side of web development to build fast, highly scalable network applications (backend)
NodeJs PROS
Single threaded, based on event driven, non blocking I/O model
Perfect for building fast and scalable data-intensive
Js accross the entire stack
npm
very active developer community
Netflix, Uber,paypal,ebay
Use NodeJS
API with database behind it(preferably NOSQL)
Data streaming
Real time chat application
Server-side web application
DON’T USE
Applications with heavy server-side processing(CPU intensive)