INT222UNIT1

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 23

INT222

Advance Web Development

BY : DIVYA THAKUR
UID:28300
Introduction
• Node.js is a javascript runtime built on chrome v8 javascript engine.
• It is a javascript running on the server.
• Node.js runs the V8 JavaScript engine, the core of Google Chrome,
outside of the browser. This allows Node.js to be very performant.
• Node.js runs on various platforms (Windows, Linux, Unix, Mac OS X,
etc.)
• in 2009. Ryan Dahl created node js

• When to use NODE JS :


• I/0 BOUND
• DATA STREAMING APPLICATIONS
• REAL TIME CHAT SYSTEMS
Installation Of Node
• Go to nodejs.org and download the version which is recommended
for most users.
• Open cmd write node -v
• Run npm -v
• IDE : Visual Studio Code
• Open visual studio code :
• run same commands as above
• one of the reaons for using visual studio code is the inbuilt terminal.

• NOTE : NPM IS NODE PACKAGE MANAGER


NODE JS REPL
• REPL is a feature of node useful for experimenting with node js code
and debugging javascript codes.
• REPL stands for :
• READ : Reads user input ,parses it into javascript data structure and
stores in the memory
• EVAL : Takes and evaluate the data structure
• PRINT: Print the result
• LOOP: Loop the command until user pressed ctrl+c twice.

The REPL is bundled with every Node.js installation and allows you to quickly
test and explore JavaScript code within the Node environment without having
to store it in a file.
• If you have node installed, then you also have the Node.js REPL.
• To start it, simply enter in your command line shell:
node
• This results in the repl prompt in cmd:
>
The > symbol lets you know that you can enter JavaScript code to be
immediately evaluated.
• Perform any operation and press enter to see the results.

• To exit the REPL, you can type .exit, or press CTRL+D once, or press
CTRL+C twice, which will return you to the shell prompt.
Executing Code in the Node.js REPL
• The REPL is a quick way to test JavaScript code without having to create a file.
Almost every valid JavaScript or Node.js expression can be executed in the
REPL.

TASKS
• Perform Operations (add,multiply,divide,subtract)
• Perform operations on strings
• Multiline Code.
• Calling Function:
• When writing Node.js code, it’s common to print messages via the global console.log
method or a similar function.
• Creating Variables
• Access last value using underscore( _ ).
• To list all the available commands, use the .help command
• All the properties ,methods inside nodejs can be seen with the help of
tapping TAB twice in REPL.
Node Package Manager
• npm is the package manager for the Node JavaScript platform. It puts
modules in place so that node can find them, and manages
dependency conflicts intelligently.
• Node Package Manager (NPM) is a command line tool that 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.
• NPM is included with Node.js installation. After you install Node.js,
verify NPM installation by writing the following command in terminal or
command prompt
npm -v
• It is extremely configurable to support a variety of use cases. Most
commonly, you use it to publish, discover, install, and develop node
programs.
• Run npm help to get a list of available commands.
• npm consists of three distinct components:
• the website
• the Command Line Interface (CLI)
• the registry
• The npm registry contains packages, many of which are also Node
modules, or contain Node modules.
• About packages
• A package is a file or directory that is described by a package.json file.
A package must contain a package.json file in order to be published to
the npm registry.
• A package.json file:
lists the packages your project depends on
specifies versions of a package that your project can use using
semantic versioning rules
makes your build reproducible, and therefore easier to share with
other developers
Package
• Downloading a package is very easy.
• Open the command line interface and tell NPM to download the
package you want.
npm install packagename
• NPM creates a folder named "node_modules", where the package
will be placed. All packages you install in the future will be placed in
this folder.
• The name npm (Node Package Manager) stems from when npm first
was created as a package manager for Node.js.
• All npm packages are defined in files called package.json.
• The content of package.json must be written in JSON.
• At least two fields must be present in the definition file: name and
version.
• npm can manage dependencies.
• npm can (in one command line) install all the dependencies of a
project.
• Dependencies are also defined in package.json.
• You can publish any directory from your computer as long as the
directory has a package.json file.
Update package
• To update the package installed locally in your Node.js project,
navigate the command prompt or terminal window path to the
project folder and write the following update command.

C:\Project> npm update <package name>


Unistall packages
• Use the following command to remove a local package from your
project.

C:\>npm uninstall <package name>


NPM Modules
• A module is any file or directory in the node_modules directory that
can be loaded by the Node.js require() function.
• To be loaded by the Node.js require() function, a module must be one
of the following:
1. A folder with a package.json file containing a "main" field.
2. A JavaScript file.
• Since modules are not required to have a `package.json` file, not all
modules are packages. Only modules that have a `package.json` file
are also packages.
• In the context of a Node program, the module is also the thing that
was loaded from a file. For example, in the following program
var req = require('request')
we might say that "The variable req refers to the request module".
Custom NPM Modules
• Node.js modules are a type of package that can be published to npm.
• Steps:
Create a package.json file
Create the file that will be loaded when your module is required
by another application
Test your module
Node JS Core Module/Built-in Module
• Consider modules to be the same as javascript libraries.
• A set of functions you want to include in your application.
• Nodejs has some built in modules.
• It is a simple or complex functiionality organised in single or multiple
javascript files which can be reused throughout node js applications.
• Core module includes functionalities of nodejs.They load
automatically when the nodejs process starts.
• However ,you have to import (require) the core modules first in order
to use it in the application.
Built-in modules
• File System Module
• Buffer Module
• Stream Module
• Timers
• Events
• HTTP ,HTTPS
• Query String
• Path

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy