# Package Management

Package management is the process of handling the many and varied dependencies and artifacts for your servers, applications, and developers. These are the archives, binaries, libraries, tools, scripts, modules, snippets, metadata, assets and even datasets that power your processes, products, and solutions.

A binary package manager centralizes these dependencies and artifacts, acting as a glue layer within the DevOps toolchain to provide easier interaction between development, operations, build, and release.

Package management reduces the friction between different functions within DevOps, and the process of delivering from developer to customer is accelerated.

### PIP

At this point you understand why we need a **package manager**.&#x20;

For python we have`pip`— a command-line **Package Installer for Python**, as the “official” package manager (there are other options to `pip` though). It simplifies the process of downloading and installing packages from PyPI and other repositories — ok, in the end is like a fancy-smart-automated copy and paste.&#x20;

Libraries installed with `pip` or other package managers will be available to `import` their packages/subpackages/modules.

Usually pip comes pre-installed along with Python’s installation.

1. Install Packages

```python
pip install flask
```

Install particular version

```
pip install flask=2.4.6
```

2. Upgrade Packages

```python
pip install --upgrade flask
```

3. Uninstall Package

```python
pip uninstall flask
```

4. Managing Dependencies

When you install libraries using `pip`, the library’s code itself is placed next to your python interpreter in the file system. Consequently, we can keep the dependencies apart from our source code.

In the virtual environment we can install our dependencies and we can use requirement files to easily install everything we need.&#x20;

Requirement files are text files where we have the dependencies of the project declared with their respective versions and sources.&#x20;

We can generate a requirement file by running `pip freeze` command and writing its output in a text file.

```python
pip freeze > requirements.txt
```

whenever we share the project or we have to setup it again, we can easily install the dependencies from the requirements file with `pip install -r requirements_file.`

```python
pip install -r requirements.txt
```

5. Testing

One of the most popular Python-based testing frameworks is Pytest, an open-source testing framework. Unit testing, functional testing, and API testing are all supported by pytest.

```python
pytest test_example.py
```

### NPM

NPM stands for **N**ode **P**ackage **M**anager and is one of the multiple package managers (others include Yarn, Bower, etc.) available for the JavaScript programming language. Furthermore, it’s the default package manager for Node.js.

NPM has a command-line client, which is generally how you install packages. What seems magical is how NPM knows what to download.&#x20;

All you do is give the name of the package you’d like, and NPM knows where to get it from. This is because NPM has an online database of public and paid-for private packages called the ***NPM registry***.

#### Basics of NPM commands

Below are the basic commands that you can use to get started with NPM.

```javascript
npm init
```

This command will create a `package.json` file in your project. You can manually add packages to this file, or you can use the `npm install` command.

```
npm install

Ex: npm install express
```

This command will look into your `package.json` file and install all the packages that are listed in the `package.json` file.

```
npm test
```

Check your code test files, execute and given a test result.

```
npm run build
```

Generate a production ready build package.

```
npm start
```

Running our application using start command.
