What is Node.js?
What is Node.js for?
Node.js does an excellent job of handling multiple connections with low cyclomatic complexity given that its single-threaded nature requires us to release the event loop as soon as possible. This makes Node.js ideal for microservices and real-time applications.
What is npm?
npm is the Node.js package manager. It consists of a command line interface that you can use to access the online registry of public and private packages.
How do I create a Node.js app from scratch?
You can start by creating a project folder. We then navigate to that folder using the command line and run npm init. Finally, we follow the instructions to fill in our app information.
What does npm install do?
It installs the dependencies found in the package.json file.
How do I install a library in Node.js?
npm install name-of-the-library will install our library and include it as a dependency. If we add the –save-dev parameter, the library will be included as devDependency.
How do I create my own script?
You need to go to package.json and add your own script in the scripts field. You can then run the script by going to the terminal and running npm run name-of-script.
Can I build a front-end application using Node.js?
The browser cannot launch a Node.js based application, but you can use something like webpack or Parcel to bundle the code and turn it into something that the browser can launch. It is now very common to use the Node.js framework to build front-end applications. A good example of using Node.js in a frontend is the Electron platform, which uses both Node.js and chromium to build “native” applications like VS Code.
Can you name three popular Node.js frameworks?
“Hello World!” with Node.js and Express
Express.js is probably the most popular framework out there today. Koajs is probably one of the fastest, and Sails.js is great for realtime two-way binding applications since they use socket.io.
Why is Express.js good?
Express.js makes it easy to set up routes for a web application, making it the best choice for building REST APIs. It”s quite flexible and easy to use, and its middleware architecture helps keep the system simple and scalable.
What is Crypto?
Crypto is an internal Node.js library that provides cryptographic functionality, such as encrypting and decrypting passwords.
How do we handle local and global scoping in Node.js?
Does Node.js have access to the filesystem?
Ultra-fast Node.js and Socket.io apps
Yes. We can use the fs module to read, write, copy and delete files and folders.
What does non-blocking mean?
This means that a piece of code, such as an asynchronous function, is scheduled to run in the next iteration of the event loop, thereby unlocking the rest of the code and allowing it to continue running.
What is an event loop and how does it work?
The event loop is what makes Node.js asynchronous. He plans to run a set of five phases in a cycle. In the first step, the scheduled setTimeout and setInterval callbacks are executed. The second runs the I / O callbacks scheduled for execution in the current iteration. The third one polls the events that will be executed in the next iteration. The fourth triggers the setImmediate () callbacks. Finally, the fifth one fires all the “close” callbacks.
Do async functions run in parallel?
Node.js vs. Deno: what you need to know
Not. The asynchronous function will execute on the next iteration of the event loop, while the parallel process runs in its own thread.
Is Node.js multithreaded?
Node.js process runs on a single thread, but if needed, you can use the child_process module to run multiple processes in parallel, or Workers to run multiple threads.
What is the child_process module?
The child_process module allows you to spawn and fork child processes. These are independent processes that run on their own processor and give us access to system commands.
What is the difference between a web worker and a worker thread?
Web workers are implemented in the browser, and worker threads are implemented in Node.js. They solve the same problem, which is parallel processing. In fact, the Worker Thread API is based on the Web Workers implementation.
What are the advantages of using a workflow over a child process?
While a child process starts its own process with its own memory space, a worker thread is a thread within a process that can share memory with the main thread. This avoids costly data serialization.
What would you use to open a two-way client connection over HTTP in real time?
We could use WebSockets or long polling. There are libraries like soket.io and SignalR that make our task easier. They even provide clients that fall back to long polling if WebSockets are not available in the browser.
Hope you found these questions helpful. Have you figured it out? If not, don”t worry. If you are not aspiring to a leadership position, you are not expected to know all the answers you need. Just make sure you understand the basics, and wherever you find a knowledge gap, try to expand it.