An Introduction of Node Package Manager (NPM)


Presentation Description

NPM is a package manager for the JavaScript programming language. It is the default package manager for the JavaScript runtime environment Node.js. It consists of a command line client, also called npm, and an online database of public and paid-for private packages, called the npm registry.


Presentation Transcript

slide 1:

iFour Consultancy Node Package Manager

slide 2:

 NPM is a package manager for the JavaScript programming language. It is the default package manager for the JavaScript runtime environment Node.js. It consists of a command line client also called npm and an online database of public and paid-for private packages called the npm registry. The registry is accessed via the client and the available packages can be browsed and searched via the npm website. The package manager and the registry are managed by npm Inc.  NPM is included as a recommended feature in Node.js installer.npm consists of a command line client that interacts with a remote registry. It allows users to consume and distribute JavaScript modules that are available on the registry. Introduction

slide 3:

 NPM is the worlds largest Software Library Registry.  NPM is also a software Package Manager and Installer.  The registry contains over 800000 code packages.  Open-source developers use npm to share software.  Many organizations also use npm to manage private development. What is NPM

slide 4:

 npm is a package manager for Node.js with hundreds of thousands of packages. Although it does create some of your directory structure/organization this is not the main purpose.  The main goal as you touched upon is automated dependency and package management. This means that you can specify all of your projects dependencies inside your package.json file then any time you or anyone else needs to get started with your project they can just run npm install and immediately have all of the dependencies installed. On top of this it is also possible to specify what versions your project depends upon to prevent updates from breaking your project. Node Package Manager

slide 5:

 It is definitely possible to manually download your libraries copy them into the correct directories and use them that way. However as your project and list of dependencies grows this will quickly become time-consuming and messy. It also makes collaborating and sharing your project that much more difficult.  Hopefully this makes it more clear what the purpose of npm is. As a Javascript developer both client-side and server-side npm is an indispensable tool in my workflow.  npm is free to use.  You can download all npm public software packages without any registration or logon. Node Package Manager

slide 6:

 npm includes a CLI Command Line Client that can be used to download and install software: Installing NPM

slide 7:

Software Package Manager  The name npm Node Package Manager stems from when npm first was created as a package manager for Node.js.  npm is installed with 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.

slide 8:

Package.Json  How to generate package.json file.  Here is Package.Json file:

slide 9:

 name − name of the package  version − version of the package  description − description of the package  homepage − homepage of the package  author − author of the package  contributors − name of the contributors to the package  dependencies − list of dependencies. NPM automatically installs all the dependencies mentioned here in the node_module folder of the package.  repository − repository type and URL of the package  main − entry point of the package  keywords − keywords Attributes of Package.json

slide 10:

Installing Packages There is a simple syntax to install any Node.js module − syntex: npm install Module Name  For example following is the command to install a famous Node.js web framework module called express npm install express We have two ways to install package. 1. Install package local 2. Install package global

slide 11:

By default NPM installs any dependency in the local mode. Here local mode refers to the package installation in node_modules directory lying in the folder where Node application is present. Locally deployed packages are accessible via require method. For example when we installed express module it created node_modules directory in the current directory where it installed the express module. local packages are installed in the directory where you run npm install package- name and they are put in the node_modules folder under this directory. For example: npm install express Install package local

slide 12:

 Globally installed packages/dependencies are stored in system directory. Such dependencies can be used in CLI Command Line Interface function of any node.js but cannot be imported using require in Node application directly. Now lets try installing the express module using global installation.  For example: npm install express -g Install package global

slide 13:

Adding dependency  Adding dependency in package.json:  For example:

slide 14:

Adding dependency  Here is Package.Json file:  express dependency package we add into package.json file

slide 15:

Update Package:  Update package.json and change the version of the dependency to be updated and run the following command.  For example: npm update express Search a package:  Search a package name using NPM.  For example: npm search express Updating packages

slide 16:

 Nodemon is a utility that will monitor for any changes in your source and automatically restart your server. Perfect for Nodejs development. Install it using npm.  Just use nodemon instead of node to run your code and now your process will automatically restart when your code changes. To install get node.js then from your terminal run:  npm install -g nodemon Installing Nodemon

slide 17:

 Automatic restarting of application.  Detects default file extension to monitor.  Default support for node coffeescript but easy to run any executable such as python make etc.  Ignoring specific files or directories.  Watch specific directories.  Works with server applications or one time run utilities and REPLs.  Requirable in node apps.  Open source and available on github. Features of Nodemon

authorStream Live Help