NodeJs

Node (or NodeJs) is a JavaScript runtime. It runs using Chromes JavaScript engine.

Node JS is a command line tool that is used to process javascripts through a command line.

For example, you can use it to execute helloworld.js with a command like.

1
Nodejs helloworld.js.

It does not support window, page, document, etc – for those you need a library (like Puppeteer)

It does however have numerous objects that can be used to your local computer. See https://nodejs.org/dist/latest-v14.x/docs/api/ for a list of those objects.

After installing NodeJs, I then installed Puppeteer. Puppeteer is a program used to simulate a Web Brower. Use this in combination with NodeJs to programmatically navigate a website and do things through code. I used this combination to recover my notes from a previous instance of MarkLandCentral.

( per https://medium.com/@bretcameron/how-to-build-a-web-scraper-using-javascript-11d7cd9f77f2 )

Npm install puppeteer

Here’s a great article describing Puppeteer
https://www.geeksforgeeks.org/node-js-puppeteer/
Looks like a program that can manage – manipulate websites.

Hints

  • To see current version installed use (node –version) at a command prompt
  • For Angular 8, the suggestion is that you run node version 12 or higher.
  • To upgrade your node, perform an uninstall, then install a fresh version.
  • When you installed Node.JS, it installed NPM (https://www.npmjs.com/)

Commands

  • [[NodeCommands]]
  • [[NpmCommands]]

Programming Topics

  • [[Folders]] - sometimes you want to manage folders within your node project.
  • [[ExitScript]]

Node – the require statement.

This is from: https://nodejs.org/en/knowledge/getting-started/what-is-require/

The rules of where require finds the files can be a little complex, but a simple rule of thumb is that if the file doesn’t start with “./“ or “/“, then it is either considered a core module (and the local Node.js path is checked), or a dependency in the local node_modules folder. If the file starts with “./“ it is considered a relative file to the file that called require. If the file starts with “/“, it is considered an absolute path. NOTE: you can omit “.js” and require will automatically append it if needed. For more detailed information, see the official docs
An extra note: if the filename passed to require is actually a directory, it will first look for package.json in the directory and load the file referenced in the main property. Otherwise, it will look for an index.js.

3rd Party Libraries that make sense to use in the context of NodeJs

  • [[Puppeteer]] - a library that allows your program to access internet websites and manipulate them.

Node the installer

I use it to install programs on my computer.

For example I was looking for a typescript definition file for google analytics. I found this website: https://www.npmjs.com/package/@types/google.analytics. It gave me an npm command to install it. it went something like this:

 cd \d\dev\node_modules
 npm install --save typescriptdefs/google.analytics

what it did was created a folder
\d\dev\node_modules\google.analytics
and placed the files I needed.

References