Training Guide: Programming in HTML5 with JavaScript and CSS3 Ebook

(Nora) #1

352 CHAPTER 8 Websites and services


After the package is globally installed, create a link to the global install from each applica-
tion that will use the global package. To accomplish this, navigate to the root folder of your
application and enter the following command.
npm link math_example

In this example, the command was executed in the math_user folder. After the command is
executed, you see that a folder called node_modules exists. If you navigate to that folder and
look at the contents of the directory, you’ll see that a math_example junction exists, as shown
in Figure 8-5.

FIGURE 8-5 he npm link command showing a junction to the global installT

A junction is a route to the global install. It behaves like a folder. You can change from the
node_modules folder to that folder by using the cd math_example command, and you can
change back to the node_modules folder by using the cd .. command.

Quick check
■■How do you install a package named contoso for local use?

Quick check answer
■■Use the following command.
npm install contoso

Now that you have installed the math_example package, write some code that accesses
the math_example package. In the math_user folder, create a JavaScript file called main.js and
enter the following code.
var math_example = require('math_example');

var result = 0;

console.log();
result = math_example.addition(5,10);
Free download pdf