How To Install NPM NodeJS On FreeBSD

Automation is the transfer of routine development tasks that can be performed manually to computers. Automation translates files written and understood by developers into compressed code that can be understood by browsers and produces the final application package.

What does automation provide.? Automation saves developers time and helps find and fix errors. This creates code that saves browser time and speeds up site loading. What tasks can be automated. For example file minification (html, css, js), image compression, capturing certain format images (webp), assembling sprite.svg files, assembling application packages.

What tools are used to automate? The programming community has created entire libraries of automation programs. There is also a system to facilitate access to this library and use it in the development of new programs and applications. One such system is the Node.js system.

To complete your knowledge about Linux applications that can run on FreeBSD systems, we recommend that you also read the following articles:

1. System Specifications
OS: FreeBSD 13.2
IP Addrees:
Node JS version:  Node.js v18.16.0
NPM version: NPM 9.7.2

2. Understanding NPM package.json

Node.js is a JavaScript interpreter that is often used to automate project assembly. Besides Node.js, we need npm package manager and Gulp task manager. The Npm package manager (node package manager) is installed automatically when installing Node.js on the server computer. Npm runs in the console and executes the commands we enter according to the syntax offered by Node.js

So in general terms, npm is a free utility for Java script developers to install and share their packages with other developers from all over the world. The name means Node Package Manager because it was originally created as the default package manager for Node.js. This tool is successfully used to manage open and private source development.

The utility npm is a package manager included with Node.js. A package is one or more js files that represent some type of library or tool. Package managers are designed to download packages from cloud servers, or to upload (publish) packages to private servers.

Using npm we can download new packages, update and remove them, share the packages we have with other users (after registering on the official site), and many more uses of npm.

3. Installing NPM package.json

Before we start installing NPM, we must first install the NPM dependency. To install dependencies from NPM, we just use the pkg package. Apart from being practical, it is also fast in the installation process.

root@ns1:~ # pkg install brotli && pkg install icu && pkg install libuv
After all the above dependencies are installed, continue by installing the node.js package, type the command below to install nde.js.

root@ns1:~ # cd /usr/ports/www/node
root@ns1:/usr/ports/www/node #
make install clean
Then install the NPM package by typing the following command.

root@ns1:/usr/ports/www/node # cd /usr/ports/www/npm
root@ns1:/usr/ports/www/npm #
make install clean
The last package that must be installed is npm-node, in this article we will install npm-node18. Type the command below to install it.

root@ns1:/usr/ports/www/npm # cd /usr/ports/www/npm-node18
root@ns1:/usr/ports/www/npm-node18 #
make install clean
Now that all the node.js NPM packages have been installed perfectly on the FreeBSD system, we can use these packages for web development or other purposes. But first, we will check the version of the package installed above. Use the command below to see the version in use.

root@ns1:~ # node --version
root@ns1:~ #
npm --version

4. How to Use NPM

The way to use NPM on FreeBSD and Linux systems and other operating systems is almost the same, perhaps the only difference is in terms of the installation process, but even then the installation process is still relatively easy. Because NPM was created to make things easier for its users.

We won't be able to use NPM packages if we don't know what commands are in NPM. The following is a list of commands that can be used when we work with NPM packages.

npm install                   install all the dependencies in your project
npm install <foo>        add the <foo> dependency to your project
npm test                       run this project's tests
npm run <foo>            run the script named <foo>
npm <command> -h   quick help on <command>
npm -l                          display usage info for all commands
npm help <term>         search for help on <term>
npm help npm              more involved overview

All commands:

    access, adduser, audit, bugs, cache, ci, completion,
    config, dedupe, deprecate, diff, dist-tag, docs, doctor,
    edit, exec, explain, explore, find-dupes, fund, get, help,
    help-search, hook, init, install, install-ci-test,
    install-test, link, ll, login, logout, ls, org, outdated,
    owner, pack, ping, pkg, prefix, profile, prune, publish,
    query, rebuild, repo, restart, root, run-script, search,
    set, shrinkwrap, star, stars, start, stop, team, test,
    token, uninstall, unpublish, unstar, update, version, view,

OK, now we will practice how to use the NPM command, for example if you want to download a package manually, for this we don't have to use package.json to do it. We can run the npm command directly with the desired package name as the command argument, and the package will be automatically downloaded to the current directory. For example, as shown below.

root@ns1:~ # npm install grunt-cli
added 59 packages in 15s
4 packages are looking for funding
run `npm fund` for details
OK, let's give an example again, in practice this time we will install Grunt using npm. Grunt is a task runner that allows you to automate many everyday tasks such as image compression and CSS file minification. Type the command below to install the Grunt application.

root@ns1:~ # npm install -g grunt-cli
added 59 packages in 2s
4 packages are looking for funding
run `npm fund` for details
With NPM we can also install packages that come from outside, for example a link or url on Github. Below is an example of installing an NPM package in the form of a URL link.

root@ns1:~ # npm install
root@ns1:~ #
npm install ""
If we want to delete a package in NPM, use the "uninstall" command, as in the example below.

root@ns1:~ # npm uninstall -g grunt-cli
removed 59 packages in 7s
NodeJS is an interesting technology that is becoming increasingly popular in large web projects. So, it is always good to install it on a FreeBSD system. In this article, we have explained the installation and use of npm for those who are new to Node.js. With this article, we should be able to use various node.js applications on the FreeBSD system.
Iwan Setiawan

I Like Adventure: Mahameru Mount, Rinjani Mount I Like Writer FreeBSD

Post a Comment

Previous Post Next Post