Full-Stack Web Development with Vue.js and Node

(singke) #1
Introducing MEVN Chapter 1

Using npm


npm is used to install different packages in our application. There are two ways to install


packages: locally and globally. When we want to install a certain package specific to our
application, we want to install that package locally. However, if we want to use a certain


package as a command-line tool or be able to access it outside our application as well, we
will want to install it as a global package.


Installing an npm package locally

To install a package specific to our application only, we can use this command:


$ npm install <package_name> --save

Installing an npm package globally

To install a package globally, we can use this command:


$ npm install -g <package_name>

Introducing package.json


All the node packages and modules consist of a file called package.json. The main


function of this file is to carry all the meta information associated with that package or
module. A package.json file requires the content to be a JSON object.


As a minimum, a package.json file consists of the following things:


name: The name of the package. This is an important part of a package.json
file as it is the main thing that distinguishes it from other packages and, hence, it
is a required field.
version: The version of the package. This is also a required field. To be able to
install our package, the name and version fields need to be given.
description: A short summary of the package.
Free download pdf