22 C
Texas
angeloma
Senior Writer and partner

How to Install GruntJS on Debian 10 / Debian 9

Web development is very popular these days. That’s why many tools are created to make coding easier. In this sense, there are some very interesting ones like Grunt which is basically a task manager for JavaScript. In this post, I will show you how to install GruntJS on Debian 10 / Debian 9. We will also do a test to demonstrate some of the potentials of this tool.

Install GrunJS on Debian. The JavaScript task runner

GruntJS is a tool for executing tasks using Javascript. It allows us to have a development of quality applications, automating as much as possible the tasks and focusing on good code. This results in a decrease in coding time and the quality of it.

Some of the things we can do using Grunt if it’s configured correctly are the following:

  • Concatenation or minimization of files CSS or JS.
  • Optimization of images.
  • The compilation ( SASS, CSS, and others).
  • Unit Test.

To perform this and other tasks, GruntJS requires plugins to be installed. That’s a lot more than 3,000.

- Advertisement -

So, now we are going to learn how to install GruntJS on Debian 9.

Install NodeJS

GruntJS uses NodeJS but we do not have to learn from NodeJS. So first we will have to install it. To do that, first, we’ll get curl and then for NodeJS.

:~# apt install curl

Now, proceed to install NodeJS 12. First, add the repository.

:~# curl -sL https://deb.nodesource.com/setup_12.x | bash -

1.- Add the NodeJS repository
1.- Add the NodeJS repository

Then we can install NodeJS. However, it is necessary to install the system compilation tools. To do this, run the following command:

:~# apt install build-essential nodejs

2.- Install NodeJS on Debian 9
2.- Install NodeJS on Debian 9

Check the NodeJS version.

:~# node -v
v12.4.0

After that, install GruntJS on Debian 9 using NPM.

:~# npm install -g grunt-cli

Finally, check the installed version.

:~# grunt --version
grunt-cli v1.3.2

Now, let us test it.

Add GruntJS to an existing project

First, place your prompt in the project directory.

:~# cd /your-project/path

Then, run the following command:

:~# npm init

3.- Set GruntJS on Debian 9
3.- Set GruntJS on Debian 9

As you can see you have to answer some questions.

Now, we have to add two files to the project. First, a .JSON file where you add the metadata of the project that NPM will read later. This is auto-generated. The second one is grunfile.js where you define the tasks and plugins that GruntJS will use.

Once you have added the .JSON file, run the next command:

:~# npm install grunt --save-dev

4.- Install Grunt on a existing project
4.- Install Grunt on an existing project

Now, create the gruntfile.js file. And create a simple task.

:~# nano Gruntfile.js
var grunt = require('grunt');
grunt.registerTask('default', 'default task description', function(){
  console.log('hello world');
});

After that, run the task.

:~# grunt

5.- Grunt is running
5.- Grunt is running

And that is it.

Conclusion

In this post, you have learned how to install GruntJS on Debian 10 / Debian 9. The process is made easier by the fact that it depends on NodeJS and is not complicated. With this tool, you can define Javascript tasks easily.

Please share this post with your friends.

- Advertisement -
Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

LEAVE A REPLY

Please enter your comment!
Please enter your name here



Latest article