Skip to content

Instantly share code, notes, and snippets.

@halitbatur
Created May 7, 2022 07:17
Show Gist options
  • Save halitbatur/5d89be2e3fe15bac3fa2fe349c7de91d to your computer and use it in GitHub Desktop.
Save halitbatur/5d89be2e3fe15bac3fa2fe349c7de91d 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?
@dilarafirtina
Copy link

Group members: Israa, Özge, Dilara
0. Differentiate between JavaScript and Node.js.
Javascript is a programming language and Node.js is a running environment based on Javascript.

  1. Why Node.js is single threaded?
    Single thread: Node JS Platform doesn’t follow the Multi-Threaded Request/Response Stateless Model. It follows the Single-Threaded with Event Loop Model. Node JS Processing model mainly inspired by JavaScript Event-based model with JavaScript callback mechanism. Because of which Node.js can handle more concurrent client requests with ease.
  2. How do Node.js works?
    Node. js runs on chrome v8 engine which converts javascript code into machine code. It is highly scalable, lightweight, fast, and data-intensive.
  3. What is package.json?
    It’s a file that holds the metadata about the npm packages and it holds the information about how to handle the project dependencies. It also gives information about the project description such as name of the project, version, author, license information etc. It is located at the root directory of the project.
  4. What is an Event loop in Node.js and how does it work?
    The event loop is what allows Node. js to perform non-blocking I/O operations — despite the fact that JavaScript is single-threaded — by offloading operations to the system kernel whenever possible. Since most modern kernels are multi-threaded, they can handle multiple operations executing in the background. When Node.js starts, it initializes the event loop, processes the provided input script which may make async API calls, schedule timers, then begins processing the event loop.
    Event loop is an endless loop, which waits for tasks, executes them and then sleeps until it receives more tasks. The event loop executes tasks from the event queue only when the call stack is empty i.e. there is no ongoing task. The event loop allows us to use callbacks and promises.The event loop executes the tasks starting from the oldest first.

@muhammed-shihebi-boot
Copy link

Hala Alkhellow
Abdul Hafiz Mhammadah
Ezgi Okur
Muhammed Şihebi

https://docs.google.com/document/d/1MJVJbfqqHqJOSYo7fFl_UKEDF8B-g81DZqUlgA_Vp2s/edit

@irem-kurt
Copy link

Group members: Yaman, Emine, Mehmet, İrem
QUESTIONS

  1. 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
    Javascript is a programming language but NodeJS is a Javascript runtime environment.
    Javascript can only be run in the browsers while we can run Javascript outside the browser with the help of NodeJS.
    JS used in client side while NodeJS is used on the server side.

Why nodejs, JavaScript is single threaded?
Similarly, within the call stack, whenever a line of code gets inside the call stack it gets executed and move out of the stack. In this way, JavaScript is a single-thread language because of only one call stack , but we can achieve multithreading by generating multiple nodes or Node.js V8 engines which in isolation are single-threaded. It is still correct to say Node.js is not multi-threaded.

  1. Node JS Web Server internally maintains a Limited Thread pool to provide services to the Client Requests. Node JS Web Server receives those requests and places them into a Queue. It is known as “Event Queue”. Node JS Web Server internally has a Component, known as “Event Loop”.

Node.js basically works on two concept
Asynchronous
Non-blocking I/O
Non-blocking I/o: Non-blocking i/o means working with multiple requests without blocking the thread for a single request. I/O basically interacts with external systems such as files, databases. Node.js is not used for CPU-intensive work means for calculations, video processing because a single thread cannot handle the CPU works.
Asynchronous: Asynchronous is executing a callback function. The moment we get the response from the other server or database it will execute a callback function. Callback functions are called as soon as some work is finished and this is because the node.js uses an event-driven architecture. The single thread doesn’t work with the request instead it sends the request to another system which resolves the request and it is accessible for another request.

3)A package. json is a JSON file that exists at the root of a Javascript/Node project. It holds metadata relevant to the project and it is used for managing the project's dependencies, scripts, version and a whole lot more.

  1. The event loop is what allows Node.js to perform non-blocking I/O operations — despite the fact that JavaScript is single-threaded — by offloading operations to the system kernel whenever possible.
  • When Node.js starts, it initializes the event loop, processes the provided input script which may make async API calls, schedule timers, or call process.nextTick(), then begins processing the event loop.

@khatibAmjad
Copy link

Team : Amjad - Mohammad Sheikh - Huzefye Abdullahoglu - Hamza

Differentiate between JavaScript and Node.js.

In web development: Javascript is executed in browser (at client side), on the other hand, Node.js designed for backend applications and Apis

Node is an environment written in C, C++, and JavaScript, and it is built on the open-source V8 JavaScript engine which also powers JS in browsers such as Google Chrome. As V8 supports new features in JavaScript, they are incorporated into Node.
runs on a server, used to make
Backend For Social Media Networking
Single-Page Applications
Chat Applications
Data Streaming
IoT Applications

Why Node.js is single threaded?
Node.js is relayed on javascript, so because JS is single threaded node.js will do so
(The single-threaded, event-driven architecture makes it very easy for handling multiple connections. An additional thread is created with each new request with Most of the popular programming languages but with Node that’s not the case.)

How does Node.js work?
It work by using the v8 engine which is the same engine that javascript uses , and node js been written with c++ language so that we can run node js on our computer as a server

What is package.json?
Package.json is a file which contain all dependencies and libraries that we install using the node package manger (npm) , so that we don’t have to upload all library to the host when we finish the program

What is an Event loop in Node.js and how does it work?
An event loop is an event-listener which functions inside the NodeJS environment and is always ready to listen, process, and output for an event. An event can be anything from a mouse click to a keypress or a timeout
Event loop waits for tasks, executes them and then sleeps until it receives more tasks. it executes tasks from the event queue only when the call stack is empty.
Sourece :
https://www.tatvasoft.com/outsourcing/2021/09/what-can-we-do-with-node-js.html

@cbaksakal
Copy link

  1. JavaScript is a programming language. On the other hand, nodeJS is an environment that uses JavaScript to make some jobs easier like I/O, networking etc. NodeJS also acts as an interpreter for JavaScript.
  2. NodeJS uses event loop model with a single thread. Async operations are queued in the event loop and callbacks are called whenever necessary.
  3. First, a request is made by the client. Then, it is added to event queue. Then we process this event. If it is a blocking one, we pass it to worker threads and it makes its way to event loop. Otherwise, it is executed directly.
  4. When you create a nodeJS project, package.json file is automatically created on the same directory. It holds metadata, dependencies and other information about the project.
  5. An event loop is an infinite loop that waits for tasks, execute them and then sleep until the next event. Event loop accepts the tasks from the event queue and allows NodeJS to perform non-blocking I/O operations and etc.

Room 6
Rasha Bsirini
Sobhan Shams
Cengiz Aksakal

@awiednoor
Copy link

These are some Node JS discussion questions to deepen your understanding of NodeJS
Differentiate between JavaScript and Node.js.
Js is a language , node js is runtime environment built in this language along with C/C++.
Why Node.js is single threaded?
Node.js use Single Threaded Event Loop Model architecture to handle multiple concurrent clients Which is inspired by js event model with js callback mechanism.
How do Node.js works?
It handles requests and responses from and to the server with a single thread, It manages files on the server
It’s build on the v8 engine which allows it to run js outside the browser
Node.js works on two concepts, Asynchronous and Non-blocking I/O
What is package.json?
It’s a json file that holds information about the project and the list of dependencies with their versions.
What is an Event loop in Node.js and how does it work?
An event loop is an event-listener which functions inside the NodeJS environment
Event loops allow node.js to be non-blocking because events are used to perform the operations in one thread.
As a single-threaded application, Node.js can support concurrency through the concept of events and callbacks. Because Node.js APIs are all asynchronous, they use async function calls to maintain concurrency. Node uses observer pattern. When a task is completed, the node thread fires the corresponding event which signals the event-listener function to run.
Event queue, the requests are placed in the event queue in a single thread, then the event loop takes each event and run the callback function related to this event.

Noor Awied, Nilay aydin & Rama Shaban

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