Skip to content

Instantly share code, notes, and snippets.

@halitbatur
Last active October 28, 2021 15:27
Show Gist options
  • Save halitbatur/016e52d308e1ced0f0bb2241e200d61f to your computer and use it in GitHub Desktop.
Save halitbatur/016e52d308e1ced0f0bb2241e200d61f to your computer and use it in GitHub Desktop.
Node js discussion questions

Node JS discussions

These are some Node JS discussion questions to deepen your understanding of NodeJS

  1. Differentiate between JavaScript and Node.js.
  2. Why Node.js is single threaded?
  3. How do Node.js works?
  4. What is package.json?
  5. What is an Event loop in Node.js and how does it work?
@Muhammeday99
Copy link

0.JavaScript is a simple programming language that runs in any browser JavaScript Engine. Whereas Node JS is an interpreter or running environment for a JavaScript programming language that holds many excesses, it requires libraries that can easily be accessed from JavaScript programming for better use.

1.Yes and no. The NodeJs event loop is a single thread. This is true.
But when this single thread encounters blocking i/o, it will delegate the task to a separate pool of worker threads. These worker threads are handled by underlying C libraries or browser extensions. Since these processes aren't directly connected to the NodeJs event loop, they are technically not "part of node".
At the end of the day, if you use NodeJs you are probably going to use more than one thread...

2.The single thread is the event loop which is responsible for running all functions and requests. The asynchronous behavior is extremely important when using node, because it guarantees that the event loop is never blocked by a synchronous function.
when a request is made the loop passes the request to an asynchronous function which does the work. When this function is done and a response is returned, it can then be passed back to the event loop to be executed by the callback and sent to the user.

3.The package.json file is a core element in the Node.js ecosystem and is basic for understanding and working with Node.js, NPM, modern JavaScript and JavaScript frameworks and libraries. The package.json is used as a manifest about applications, modules and packages. It's a tool to make modular and efficient applications.
It records important metadata about a project which is required before publishing to NPM, and also defines functional attributes of a project that npm uses to install dependencies, run scripts, and identify the entry point to our package.

4.when a request is made the loop passes the request to an asynchronous function which does the work. When this function is done and a response is returned, it can then be passed back to the event loop to be executed by the callback and sent to the user.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment