If you are working with JavaScript, it is simply nice to have Node.js and npm available to use.
- On Windows, use the installer from the node website.
- On macOS, use Homebrew to install node.
- On Linux, I prefer to install from a package manager.
Depending on who else and where else code must run, there are many options for installing command-line interface tools for working with JavaScript.
This can sometimes be the most portable and easily setup way to use these tools.
Make sure package.json exists before installing any dependencies to save them.
Node comes with npx now, which simplifies running commands from devDependencies.
$ npm i -D babel-cli
$ npx babel src/example.js -o dist/example.jsYou can also use the commands directly within package.json:
{
"scripts": {
"build": "babel src/example.js -o dist/example.js"
},
"devDependencies": {
"babel-cli": "latest",
"babel-preset-env": "latest"
}
}$ npm run buildMany, many JavaScript tools have a package available on npm. Installing a package globally lets a developer use that tool in any terminal on that computer.
Think of it as being similar to apt install on Linux machines, so package.json or npx are unnecessary to run the command.
Use sudo on Linux only. Avoid using sudo npm i -g anything on macOS to keep the global modules' permissions clean.
$ sudo npm i -g typescript
$ tsc --versionDownloading an installer from a project's website. Typescript, for instance, requires that you install this way to work with VS Code or Visual Studio.
Tools installed as system programs can be more difficult to update, but have better integration with other programs.