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

Room 2 answers :
0. JS is a language but node.js is framework for running JS on server side.

  1. Because it improves the efficiency by speeding up the response of the request.
  2. It's an event driven environment running on V8 engine.
    3.It's a file that contains all the external dependency packages and the functional attributes (metadata) which are required to our project.
  3. It's the heart of node.js it runs infinite loop which waits for the tasks and execute them and sleep until it receives a new one.

@felmez
Copy link

felmez commented Oct 26, 2021

  1. javascript is simply and programming language where you can make interactive web pages and it runs inside the browser. on the other hand NodeJS is a framework or a runtime environment that translated javascript codes to it can be running outside the browser.
  2. being a single threaded use less resources that being a multi threaded, so each time i run a server it will reserve a thread and do all the stuffs using it and this giving more advantage because javascript is already a single threaded language so they support each other perfectly
  3. nodejs is using event driven architecture so each request acts like an event and it translated to commands through the engine
  4. package.json file is like the center of a node.js app. It holds the data, attributes and dependencies for a project.
  5. In computer science, the event loop is a programming construct or design pattern that waits for and dispatches events or messages in a program. The event loop works by making a request to some internal or external "event provider", then calls the relevant event handler

Team: @AmmarBaki2 @Amr-Nash @mehmetfatiherdem

@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