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?
@ZuluNovember
Copy link

Differentiate between JavaScript and Node.js.
NodeJS is a runtime environment that allows the javascript to be run on the server-side.
Javascript is a Scripting language that is generally used for web applications

Why Node.js is single threaded?
NodeJs was built with the intention of supporting asynchronous operations.... and the fact is that the asynchronous operations have better performance and scalability when they are single-threaded over multi-threaded. This is the reason the NodeJs is single threaded.

How do Node.js works?
Node Js works on V8 engine which powers chromium based web browsers and microsoft edge. It uses event-loop.

What is package.json?
Package.json has all the installments and dependencies that we need in order to run the project.

What is an Event loop in Node.js and how does it work?
Event loop is an endless loop, which waits for tasks, executes them and then sleeps until it receives more tasks.

@yaman3bd
Copy link

  1. Differentiate between JavaScript and Node.js.
    Javascript is a front-end development env
    and node js is a server-side development env

  2. Why Node.js is single-threaded?
    because it is a none blocking-language
    so it does not need multi-thread

  3. How do Node.js works?
    first, the event loop takes the user request, and then,
    register a callback in the queue and after the operation is completed,
    it will trigger the registered callback

  4. What is package.json?
    basically, it is a JSON based file that registers all our project dependencies

  5. What is an Event loop in Node.js and how does it work?
    the event loop is the connection between the Event queue and thread Pool
    and it takes the requests from the user and adds them to the event queue then after the operation is complete

@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