Nenba Jonathan

Software Developer

Blog

« back

Package management basics for web developer

Posted on by Jonathan Nenba | Read comments
package npm yarn pip go modules

As a developer, you will realize that most of the time we will write code and try to solve problems by writing code, from day to day a repetition will be created not only in the project you are working on but also when you will switch between different projects, sometimes it will be small implementations and sometimes big changes that will push you to copy and paste big blocks of code.

Many developers have been facing this dilemma since the beginning of time and many solutions have been proposed, so I’d like to discuss today about the package manager.

A package manager is a tool or application that allows developers to add and manage dependencies in their projects (or add them to your project and also the possibility to write your own packages.)

In reality you don’t need the packager manager, you can do it manually, download and reference the library in your code and use it, but it will become very tedious especially when the list starts to become big and you should take into account the different versions compatible with your code base.

For the package manger to work, it must know where it has to go to get the dependencies, this is where the Package Registry comes in. So we can define them as a warehouse where are stored the different packages according to their version, in this way the developer can decide which version of a package he wants to add in his project. It should also be noted that it is possible to have its own package registry often used for packages specific to a company.

The package manager differs from the programming languages, we will discover the most used for which programming languages: Javascript, Python and Go

Javascript

The most popular package manager in javascript is npm, it comes as soon as you install node in your machine. By initializing your application to use npm, it will create a package.json file in your project, it will contain the different information of your application and also the list of all the dependencies you had used in your project.

npm init
npm install axios

The second package manager is yarn, which respect the same principle of operation as npm, it also has its specificity I invite you to read this article

The most used package registry for these package manager are NPM Registry and Github Packages.

Python

Like npm(Node Package Manager) and Yarn(Yet Another Resource Negotiator), python also has its own package registry which is The Python Package Index (PyPI) which is the repository that contains all the applications that you can add to yours as depandances.

By installing python you get pip which is the standard package manager of python, next to that you find Pipenv and Postry which are also very successful in the community.

pip install faker

Or you can launch the installation from your requirements.txt file(this file content the list of depqndqnies to the projet with their version)

pip install -r requirements.txt

little tip to use to create a requirement file that will contain the list of all your depandancies

pip freeze >> requirements.txt

Go

Go Modules is the easiest way to manage your depandaces in Go, to initialize it you just have to launch the command

go mod init

This command will create the go.mod which is the equivalent of the package.json file for javascript. To add a package you have to run the command go get … followed by the reference of your package, it can be a name from the official go registry or the link to a go package on Github.

go get github.com/rs/zerolog@v1.14.3
go get github.com/go-chi/chi@master

package management in projects is a bigger topic, I hope we will have time to share more in the future, this post was intended to briefly introduce you to the different package managers and their use.