0% found this document useful (0 votes)
12 views13 pages

2022 S1 - SE3040 Lecture 03

This document provides an overview of Node.js, an open-source JavaScript runtime environment for building server-side and networking applications. It discusses how Node.js uses an event-driven, non-blocking I/O model to handle a large number of simultaneous connections efficiently. The document also covers Node.js use cases, advantages like scalability, its package manager npm, and how to require and use modules in Node.js applications. It concludes with examples of basic coding tasks that can be done in Node.js.

Uploaded by

My Soulmate
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views13 pages

2022 S1 - SE3040 Lecture 03

This document provides an overview of Node.js, an open-source JavaScript runtime environment for building server-side and networking applications. It discusses how Node.js uses an event-driven, non-blocking I/O model to handle a large number of simultaneous connections efficiently. The document also covers Node.js use cases, advantages like scalability, its package manager npm, and how to require and use modules in Node.js applications. It concludes with examples of basic coding tasks that can be done in Node.js.

Uploaded by

My Soulmate
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 13

Application

frameworks

NodeJS

1
Overview
● NodeJS
● Event loop
● Use cases
● Advantages and disadvantages
● Package manager
● Require
● Let’s do coding
NodeJS
● Developed by Ryan Dahl.
● Created with the aim of creating real-time websites with push capabilities
(websockets).
● NodeJS is an open source, cross platform runtime environment for server-
side and networking applications.
● Build on V8 engine, Chrome’s JavaScript engine.
● Uses event-driven, non-blocking I/O model which makes NodeJS
lightweight and efficient.
● Ideal for data-intensive real-time applications that run across distributed
devices.
● NodeJS comes with several JavaScript libraries that help basic
programming.
● NodeJS eco-system ‘npm’ is the largest in the world for open source
libraries.
Event loop
Use cases
● Not the best platform for CPU intensive heavy computational applications.
● Ideal for building fast and scalable network applications.
● NodeJS is capable of handling a huge number of simultaneous connections
with high throughput.
● For each connection NodeJS does not spawn new Thread causing max out of
memory instead handle all in single thread using non-blocking I/O model.
● NodeJS has achieved over 1 Million concurrent connections.
● Bubbling errors up to NodeJS core event loop will cause crashing the entire
program.
Use cases
● I/O bound applications.
● Data streaming applications.
● Data intensive real-time
applications.
● JSON APIs based applications.
● Single page applications.
Advantages
● Ability to use single programming language from one end of the
application to the other end.
● NodeJS applications are easy to scale both horizontally and vertically.
● Delivers improved performance since V8 engine compile the JS code
into machine code directly.
● Performance increased via caching modules into memory after the first
use.
● Easily extensible.
● Support for common tools like unit testing.
● Well build ‘npm’ package manager and it’s large number of reusable
modules.
Disadvantages
● Even though there are number of libraries available, the actual number of
robust libraries is comparatively low.
● Not suitable for computationally intensive tasks.
● Asynchronous programming model is complex than synchronous model.
Node package manager
● Reusable NodeJS components easily available through online repository.
● Build in version and dependency management.
● Build in scripting mechanism.
● Global installations will be available throughout the system while local
installations will only be available for that particular application.
● By default all the dependencies will get installed to ‘node_modules’
directory.
● ‘package.json’ contains all information related to the NodeJS application.
The file be placed in the root directory of the application.
● ‘package.json’ will contain name, version, author, repository, required
node version, scripts and dependencies etc.
Node package manager…
● To denote the compatible version numbers npm has mechanism for
defining them;
● Less than or equal ‘<=’, greater than or equal ‘>=’.
● Approximately equivalent to ‘~’.
● Compatible with ‘^’.
● Any ‘*’.
● Any ‘1.2.x’.
● Latest ‘latest’
● There are two types of dependencies ‘devDependencies’ (development
time dependencies) and ‘dependencies’ (application runtime
dependencies).
Node require
● NodeJS follows commonJS pattern when loading modules.
● Require modules get loaded synchronously and will be cached after the
first use.
● If the file does not start with ./, ../, or / module is not a core module
NodeJS will look the dependency on the node_modules directory.
Let’s do some coding
● Hello world.
● Read file.
● Write file.
● Stream the content of a file.
● Create event and subscribe to it.
● Create a child process and message passing between two processes.
● Create a web server and listen to a port via http protocol.
● Add a separate module and use it.
● Use a promise.
13

You might also like