Pure Programmer
Blue Matrix


Cluster Map

Dependency Management

L1

This page is under construction. Please come back later.

It is often easier to write programs when you don't have to write all the code from scratch. There are a large number of code libraries available, both open source (free) and commercial (paid). Using code libraries written by the community or commercial developers give you a leg up in your coding efforts by making a large library of useful functions and classes available to your program. All we need to do is manage these dependencies and include them in our programs.

Since Javascript is an interpreted language, all you need to do to use pre-written code is to download the .js file, put it in your project folder and then include it in your program. If you are writing Javascript for use in the web browser, this means adding an script element in the head section of your webpage. For example:

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8" />
	<title>Javascript Example</title>
	<script src="Utils.js"></script>
</head>
Including Javascript Files from HTML

If you are running Javascript from the command line using [[node.js]], then you will want to use the [[Node Package Manager (npm)]] software that comes with node to download and install libraries for you. The community maintains a large online library of [[node.js]] packages that you can access using npm. Given the name of a module such as sax, you can download it and install it in one step from the command line:

$ npm install sax added 11 packages, removed 5 packages, changed 1 package, and audited 16 packages in 2s found 0 vulnerabilities

As with HTML you can also just put the .js file in the same folder as your program. For example download the [[Pure Programmer JavaScript Utils Module]] and place it in your project folder. Then add a require to the beginning of your source file:

var Utils = require('./Utils');
Including Javascript Files in node.js

References