Appendix F Node and npm
To run a Javascript program outside a web browser requires a program that can interpret the Javascript language. A popular choice is
node.js, whose executable is simply node. Programs designed for execution by node often build on other programs. These are all organized in packages, which can be managed by the Node Package Manager, known as npm for short. A basic purpose of npm is to manage versions and dependencies among packages.
So the first step is to install both
node and npm on your system. Instructions for installing node and npm can be found at nodejs.org. These programs are meant to be cross-platform, so once you do these two operating-system-specific installations, we can proceed with generic instructions.
Now
node should be on your path, and you can trywhich node
to see if your operating system can locate it automatically. If not, then you will need to edit your personal copy of the
pretext.cfg configuration file to have the node key provide a path to the executable (see Section 47.6).Some useful
npm commands are listed below, in the form of examples. These commands depend on running in a package a folder containing a file named “package.json”. So before trying to run any of them, make sure to navigate to such a folder (e.g. script/mjsre or script/cssbuilder). In particular, note npm install which must be run before using a script.
When using node with git (see Appendix I), you generally should should check
package.json and package-lock.json into source control, but ignore the entire node_modules folder.
npm commandsnpm install |
Install the packages listed in the “package.json” file to the folder node_modules. This is required one time before you use a package. |
npm list |
Full tree of installed packages (local) |
npm list mathjax-full |
Just one package |
npm view speech-rule-engine version |
Available version |
