NodeJS


Node.js is an open-source and cross-platform JavaScript runtime environment for server-side and networking applications. Node.js was developed by Ryan Dahl in 2009 and its latest version is v0.10.36. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices. Node.js applications are written in JavaScript and can be run within the Node.js runtime on OS X, Microsoft Windows, and Linux.

Features of Node.js

  • Asynchronous and Event-Driven 
  • Very Fast 
  • Single-Threaded but Highly Scalable
  • No Buffering
  • License

Where to Use Node.js?

  • I/O bound Applications
  • Data Streaming Applications
  • Data-Intensive Real-time Applications (DIRT)
  • JSON APIs based Applications
  • Single Page Applications

Advantages of Node.js

  • Scalability
  • Single programming language
  • Freedom to develop a cross-platform app
  • High performance
  • Extensibility
  • Simple to learn
  • Large community support
  • Web app development speed
  • Improved app response time
  • caching

Disadvantages of Node.js

  • Unstable API
  • Lack of library support
  • High demand for experienced resources
  • Heavy computing tasks
  • Asynchronous programming model

What can we do with Node.js? 
  • Complex SPAs
  • RTAs
  • Chat rooms
  • Browser Games
  • Data Streaming Apps
  • REST APIs
  • Server-side web apps
  • Command-line tools
  • Hardware programming

Event Loop

The event loop is what permits Node.js to conduct non-blocking I/O operations despite the fact that JavaScript is single-threaded by offloading operations to the system kernel whenever available.


Phases of Event Loop

  • timers: Executes callbacks scheduled by setTimeout() and setInterval().
  • pending callbacks: Executes I/O callbacks deferred to the next loop iteration.
  • idle, prepare: Only used internally.
  • poll: Retrieve new I/O events and execute I/O-related callbacks.
  • check: setImmediate() callbacks are invoked here.
  • close callbacks: Some close callbacks.

References
  • https://www.tutorialspoint.com/nodejs/nodejs_introduction.htm
  • https://railsware.com/blog/what-is-node-js-used-for/#How_it_works
  • https://www.mindinventory.com/blog/pros-and-cons-of-node-js-web-app-development/
  • https://nodejs.org/en/docs/guides/event-loop-timers-and-nexttick/



Comments