1 / 17

An Introduction of Node Package Manger (NPM)

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.

Download Presentation

An Introduction of Node Package Manger (NPM)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Node Package Manager iFour Consultancy https://www.ifourtechnolab.com/nodejs-blockchain-software-development

  2. Introduction • 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. https://www.ifourtechnolab.com/nodejs-blockchain-software-development

  3. What is NPM? • NPM is the world's largest Software Library (Registry). • NPM is also a software Package Manager and Installer. • The registry contains over 800,000 code packages. • Open-source developers use npm to share software. • Many organizations also use npm to manage private development. https://www.ifourtechnolab.com/nodejs-blockchain-software-development

  4. Node Package Manager • 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 project's 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. https://www.ifourtechnolab.com/nodejs-blockchain-software-development

  5. Node Package Manager • 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. https://www.ifourtechnolab.com/nodejs-blockchain-software-development

  6. Installing NPM • npm includes a CLI (Command Line Client) that can be used to download and install software: https://www.ifourtechnolab.com/nodejs-blockchain-software-development

  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. https://www.ifourtechnolab.com/nodejs-blockchain-software-development

  8. Package.Json • How to generate package.json file. • Here is Package.Json file: https://www.ifourtechnolab.com/nodejs-blockchain-software-development

  9. Attributes of Package.json • 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 https://www.ifourtechnolab.com/nodejs-blockchain-software-development

  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. • Install package local • Install package global https://www.ifourtechnolab.com/nodejs-blockchain-software-development

  11. Install package local • 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 https://www.ifourtechnolab.com/nodejs-blockchain-software-development

  12. Install package global • 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 let's try installing the express module using global installation. • For example: $ npm install express -g https://www.ifourtechnolab.com/nodejs-blockchain-software-development

  13. Adding dependency • Adding dependency in package.json: • For example: https://www.ifourtechnolab.com/nodejs-blockchain-software-development

  14. Adding dependency • Here is Package.Json file: • express dependency (package) we add into package.json file https://www.ifourtechnolab.com/nodejs-blockchain-software-development

  15. Updating packages 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 https://www.ifourtechnolab.com/nodejs-blockchain-software-development

  16. Installing Nodemon • 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 https://www.ifourtechnolab.com/nodejs-blockchain-software-development

  17. Features of Nodemon • 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. https://www.ifourtechnolab.com/nodejs-blockchain-software-development

More Related