Node.js | ![]() |
---|
This metawork article describes Node.js (aka node). Node runs JavaScript on a development computer (aka server), compared to running JavaScript in a web browser (aka client). The Node Package Manager (npm) is a package manager for the JavaScript programming language maintained by npm, Inc.
Prebuilt Installer
then the latest version of Node.js for Windows running x64Download Node.js v22.11.0
button to download the msi fileC:\Program Files\nodejs
folderNote: The Node Package Manager (npm) is automatically installed when Node.js is installed. To see what versions you have of node and npm, please open the command window. For Windows 11, enter "cmd" in the search box to open the Command window.
node -v
npm -v
To update npm, type: npm install -g npm
Here are ways to maintain TypeScript. If you want to learn how to compile, please see my metawork article after reading this article.
The default location for node modules is the %UserProfile%/appdata/roaming/npm/node_modules
folder. To change the location type:
npm config set prefix "C:\projects\npm"
Use npm to install the TypeScript compiler tsc
. See instructions here.
npm install -g typescript
npm update -g typescript
This installs the TypeScript files in the C:\projects\npm\node_modules\typescript
folder but note that tsc.cmd
is in the C:\projects\npm
folder.
tsc -v
Please read my article on TypeScript to learn more. And my article on Build JavaScript Files explains how to compile TypeScript files to JavaScript.
Most of my automation is done by the Filer.js module in the metawork/server folder. Note: When running on the server (node mode), the Viewer object references the filer in the server folder. When running in the browser, the Viewer object references a stub in the viewer folder.
JavaScript files with the extension ".mjs", which indicates to Node.js it is a module file. I name my JavaScript "metaworkers" in all lowercase with hyphens for spaces. The first line in the file "hints" that the following JavaScript targets version ES6:
/* jshint esversion: 6 */
This version introduced keywords like import
and const
. To run a JavaScript module, you first need to open a Terminal window, and change the current working directory (cwd) to where the module resides. Then you execute the script using node
. The following example is for my development computer:
cd /projects/mysterymaster.com/metawork/js/server node my-name.mjs