introduction
Simply : javascript from the command line. Rhino does that as well but... But like it is in the browser, for instance console.log() just works and also you get more modules installable through npm the nodejs package manager.
installation
Node and npm have to be setup correctly. A default install seems to lead to npm -g installing everything in /usr/lib/node_modules and we need root permissions there.
never do sudo npm -g install ...
Since anyone can virtually post a package on the npm repositories, we could end up with a malicious script with root permissions.
If you are already seeing npm -g using /usr/lib, try reinstalling it according to this link : visit
Install from tar file or with nvm
This is for newer versions !!. On debian apt-get install nodejs gives you V12 and that seems to do fine !!
The first one is better because with nvm you seem to have to type this every single time you start a new shell.
| use node | |
|---|---|
So you will probably do the tar install anyway to get rid of it. The tar install is simply unpacking and adding that location to your path.
tar file
browse to visit to pick a version you want. or..
| install | |
|---|---|
nvm
Here are the steps from there in terse mode
If new shells fail to find npm it might help to run this command again
use another global prefix
To avoid getting :
You getter change the prefix to one you can write to ! For instance ~/.npm
| config | |
|---|---|
Ok, it installs but your new prefix is not in your path, simply add this to your PATH in ~/.bashrc or ~/bin/kees.sh :
| set path | |
|---|---|
Now you don't need to use sudo anymore.
npm
package.json
Later.. but know that using --save stores an entry in this file and you can steer versions in this file and then just run :
| install | |
|---|---|
loglevel and warnings
One of the eyesores about npm is warnings like this :
| warnings | |
|---|---|
This is ugly and totally unnecessary, because it is only needed on osx as the warning clarifies. So i don't want to see warnings, this can be steered with the --loglevel=error commandline option. That's a bit long to type each time. You could also use -s because that means --loglevel=silent, but i don't know if that suppresses errors as well.
Better
| config list | |
|---|---|
This will print the currently set options. You can see what exactly a parameter should be, in this case :
You can use the 'ole' way of rc files to change commandline options. An easy way to do this is to use npm config.
| loglevel | |
|---|---|
This will create the file ~/.npmrc with these contents.
| ~/.npmrc | |
|---|---|
So yes you could do that by hand, but this guarantees the correct filename and syntax. If you want it on a per-package base, you should put a .npmrc in the current directory which will override the global one in your home directory. In fact the npm config reports the decisions about overrides. Here is the output when you have a local .npmrc with loglevel=silent, and a global one with loglevel-error:
| view loglevel | |
|---|---|
npm audit
This command runs a security audit on your project, and also all used packages. When you run npm audit you will get a list of vulnerabilities, and you can run a fix to fix them :
The last one is needed if there are fixes that cannot be installed without force. But still --force will fail for some updates. For instance :
You will have to decide on this report what to do.
npm and bootstrap
Error
91% additional chunk assets processingError: ENOENT: no such file or directory, open 'D:\ANGUALRJS2 PROJECTS\NG2CLIAPP01\src\node_modules\bootstrap\dist\js\bootstrap.min.js' #9438
Or similar message during bootstrap installation. The main problem is that some installations put the node_modules directory in the current directory, and some one level higher.
The example installation showed to import some .js and .css files from '../node_modules' while the current angular installation just seems to install all modules under './node_modules'.
This made clear which of the two is used :
| clear and reinstall | |
|---|---|
The entries in angular.json with ../node_modules al had to be changed and after that everything works again.
SyntaxError: Cannot use import statement outside a module
That error, when using import can't be understood by plain nodejs. Here is an example file that will fail :
import is an ECMAScript 6 directive, so you have to install and use it :
Source: visit
The other way (CommonJS) is to user require :
Now you don't need the -r esm option.
Sometimes you see this syntax, but i have not found how that is supposed to work ?!?