Nodejs intro

Содержание

Слайд 2

AGENDA

What is NodeJS?
Blocking and Non-blocking I/O
REPL Console
NPM & Module System
Global Objects
Filesystem module
HTTP

AGENDA What is NodeJS? Blocking and Non-blocking I/O REPL Console NPM &
Module

Слайд 3

What is NodeJS ?

NodeJS is an open source , cross platform runtime

What is NodeJS ? NodeJS is an open source , cross platform
environment for server side and networking applications
It is written in C/C++ & JavaScript and can run on Linux , Mac , Windows
It provides an event driven architecture with non blocking I/O that is optimal for scalability.
It uses Google JavaScript V8 Engine to Execute Code

Слайд 4

JAVASCRIPT V8 ENGINE
V8 is an open-source JavaScript engine developed by The Chromium Project for Google Chrome and Chromium web browsers.
V8

JAVASCRIPT V8 ENGINE V8 is an open-source JavaScript engine developed by The
compiles JavaScript to native machine code before executing it
V8 can run standalone, or can be embedded into other application

Слайд 5

Input/Output (I/O)

Input/Output (I/O) is the communication between an information processing system, such

Input/Output (I/O) Input/Output (I/O) is the communication between an information processing system,
as a computer, and the outside world, possibly a human or another information processing system.
Inputs are the signals or data received by the system
Outputs are the signals or data sent from it.

Слайд 6

BLOKING I/O

Blocking is when the execution of additional JavaScript in the Node.js process

BLOKING I/O Blocking is when the execution of additional JavaScript in the
must wait until a non-JavaScript operation completes. 

Слайд 7

NON-BLOCKING I/O

In Non-blocking I/O once the request is made we continue on

NON-BLOCKING I/O In Non-blocking I/O once the request is made we continue
to the next line of code before waiting for the time consuming request to finish.

Слайд 8

NODEJS SETUP

https://nodejs.org/en/download/

NODEJS SETUP https://nodejs.org/en/download/

Слайд 9

REPL CONSOLE

REPL CONSOLE

Слайд 10

REPL CONSOLE

REPL CONSOLE

Слайд 11

REPL CONSOLE

REPL CONSOLE

Слайд 12

REPL COMMANDS

REPL COMMANDS

Слайд 13

NODE PACKAGE MANAGER

Node Package Manager (NPM) is a command line tool that

NODE PACKAGE MANAGER Node Package Manager (NPM) is a command line tool
installs, updates or uninstalls Node.js packages in your application. It is also an online repository for open-source Node.js packages. The node community around the world creates useful modules and publishes them as packages in this repository.
https://www.npmjs.com/

Слайд 14

INSTALLING A NPM MODULE

All the modules installed using NPM are installed

INSTALLING A NPM MODULE All the modules installed using NPM are installed under node_modules folder.
under node_modules folder.

Слайд 15

PACKAGE.JSON

The package.json file is kind of a manifest for your project. You

PACKAGE.JSON The package.json file is kind of a manifest for your project.
can add a it to your package to make it easy for others to manage and install. Packages published to the registry must contain a package.json file.
A package.json file:
lists the packages your project depends on
specifies versions of a package that your project can use
makes your build reproducible, and therefore easier to share with other developers

Слайд 16

MODULES IN NODEJS

NodeJS Module system lets developers create a manageable structure of

MODULES IN NODEJS NodeJS Module system lets developers create a manageable structure
their application
Each module is just a JavaScript file with code (functions, variables, objects, etc.)
In Node, modules are referenced either by file path or by name
Referenced by name modules are either core modules (preinstalled with Node) or third-party modules installed using NPM
Each module exposes public API that the developer can use after the module is imported into the current script

Слайд 17

LOADING AND EXPORTING MODULES

To load/import a module, you have to use the

LOADING AND EXPORTING MODULES To load/import a module, you have to use
require function
The require function returns an object that represents the JavaScript API exposed by the module
Depending on the module, that object can be any JavaScript value — a function, an object with some properties that can be functions, an array, or any other type of JavaScript object

Слайд 18

LOADING AND EXPORTING MODULES

To export an object/function/variable from a module, use the

LOADING AND EXPORTING MODULES To export an object/function/variable from a module, use the module.exports object
module.exports object

Слайд 19

GLOBAL OBJECTS

These objects are available in all modules:
process - In computing,

GLOBAL OBJECTS These objects are available in all modules: process - In
a process is an instance of a computer program that is being executed.
console - For printing to stdout and stderr.
require - used to load or import local files, JSON and modules..
__filename – returns the absolute path of the file being executed. It is not available in the Node.js REPL..
__dirname – returns the path of the directory the script is executing in. It is not available in the Node.js REPL.
module.exports is used for defining what a module exports and makes available through require().
setTimeout(cb, ms) – Run callback cb after at least ms milliseconds. The timeout must be in the range of 1-2,147,483,647 cannot span more than 24.8 days.
clearTimeout(t) – Stop a timer that was previously created with setTimeout().
setInterval(cb, ms) – Run callback cb repeatedly every ms milliseconds
clearInterval(t) - Stop a timer that was previously created with setInterval().

Слайд 20

FILE SYSTEM MODULE
The fs module provides a lot of very useful functionality

FILE SYSTEM MODULE The fs module provides a lot of very useful
to access and interact with the file system.

Слайд 21

FILE SYSTEM MODULE
The asynchronous API is used with a callback:
A synchronous API

FILE SYSTEM MODULE The asynchronous API is used with a callback: A
can be used like this, with a try/catch block to handle errors:

For example let's examine the fs.rename() method:

Слайд 22

HTTP MODULE

It is easy to create an HTTP server in Node.js. A

HTTP MODULE It is easy to create an HTTP server in Node.js.
Node server is typically created using the createServer method of the http module and run this with
Имя файла: Nodejs-intro.pptx
Количество просмотров: 42
Количество скачиваний: 0