Install some Packages before doing NodeJS project

Tram Ho

Begin

Continuing on the basic Nodejs series today, I will introduce some of the things that I think are necessary when doing a Nodejs project (fighting the enemy requires preparing weapons, right?  In this article, I will introduce to everyone that is Yarn and Nodemon In addition, the figure will also introduce the custom statements running the nodejs project. Let’s find out the details one by one

Yarn

What is Yarn?

Yarn is a fast, reliable, and secure open source javascript library management tool to replace NPM. Yarn has advantages over npm like:

  • YARN downloads many packages at the same time so the download speed will be faster than downloading each package one by one like npm .
  • YARN will create cache for all downloaded packages, support offline installation …

There are many advantages of yarn but in the scope of this article, I would like to not go into detail on this issue. As long as you know Yarn is made by big companies like facebook, google …, how can it not be good, not good.  In the previous post, I installed Nodejs and already had npm already, so I will install Yarn through npm . To install, just open up a terminal and run the command:

-g stands for global meaning that if you install yarn globally, just open a terminal and you’ll already have yarn there. To check if yarn installed successfully, just type:

It looks like this is a successful install

Next we will install nodemon

Nodemon

What is Nodemon?

Nodemon is a tool that helps to efficiently develop Nodejs applications by automatically relaunching the application when it detects a change in the files. @@ in lesson 2, the introduction of nodemon also a bit confusing, actually I intend to introduce it in the next post but after thinking about it, I recommend installing yarn nodemon , so I recommend installing nodemon , standard one time and then the following articles just need to code . It is lengthy, but in short, you just need to understand that when you change the code, you have to turn off the server and then run the command node index.js then it will execute what you have changed, lose your job v ~ . Now that you install nodemon on, it will perform on your behalf but you do not need to do anything more convenient. Now there is yarn so I will install nodemon with yarn just run the command:

--dev here is to save it to devDependencies in package.json because I just want to install nodemon in the develop environment. This I also said in the previous post . Next will be the installation of the command to run Nodejs .

Miscellaneous set

In the previous post, we already know that the command to run Nodejs is node index.js , now I don’t want to run that command anymore, everyone is the same. Simply add a little bit in the package.json file. You just need to modify the scripts like this

Now open up terminal and run

See the results, actually, the results are the same as the first post I ran with the command node index.js : v. Here you see dev = with node index.js so it actually runs yarn node index.js : v. So you can replace the word dev with whatever word you want, remember that by running yarn + the word you replace will be: v.

Conclude

So I have finished introducing a package and installed some miscellaneous things that I feel necessary to start learning nodejs , of course, in fact, when doing the project, there are many package to install. But when we need to use those things, we will install them. In this post, I would like to stop here, in the next post I will continue to learn about the basic components of Nodejs such as Template engines Query parameters .. .If you have any questions or add anything to the article, please click below to let the mine know. Thank you for watching.

Share the news now

Source : Viblo