Node.js Scroll To Bottom


nodejs

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.

Install Node.js

  1. Set your browser to: https://nodejs.org
  2. Click the "package managers" link
  3. Select the Prebuilt Installer then the latest version of Node.js for Windows running x64
  4. Click the Download Node.js v22.11.0 button to download the msi file
  5. Run the msi file to install Node.js to the C:\Program Files\nodejs folder
  6. In the "Tools for Native Modules" window DO NOT check the box for automatic install of necessary tools.

Note: 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.

Show Versions of node and npm

  1. Show Node.js version (I have "v22.11.0"): node -v
  2. Show npm version (I have "10.9.0"): 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.

Set Location of Node Modules

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"

Install/Update TypeScript

Use npm to install the TypeScript compiler tsc. See instructions here.

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.

Add TypeScript Compiler to Path (Windows 11)

  1. In Search box type: "Advanced System Settings"
  2. In "System Properties" window click the "Environment Variables" button
  3. In "Environment Variables window select "Path" and click the "Edit" button
  4. In "Edit Environment Variable" window click the "New" button
  5. Add "C:\projects\npm" (no quotes) and click the "OK" button

Show Version Of TypeScript

  1. Enter "cmd" in search box to open Command window (Windows 11)
  2. Show TypeScript version (I have "5.7.2"): 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.

Node Automation

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