Managing Dependencies and Lock Files

Learn to make a centralized dependency file and to produce a lock file with the dependency file.

Dependency management

Previously, we learned how Deno enables us to do dependency management. In this lesson, we’ll use dependency management in a more practical context. We’ll start by removing all the scattered imports with URLs from our code and move them into a central dependency file. After this, we’ll create a lock file that makes sure our still young application runs smoothly anywhere it’s installed. We’ll finish by learning how can we install the project’s dependencies based on a lock file.

Creating a centralized dependency file

Previously, we were using direct URLs to dependencies directly in our code. Even though this is possible, this was something we discouraged a few chapters ago. Using direct URLs worked for us in the first phase, but as the application starts growing, we’ll have to manage our dependencies properly. We want to avoid struggles with conflicting dependency versions, typos in the URLs, and having dependencies scattered across files. To solve this, we must create a centralized dependency file like this:

  1. Create a deps.ts file at the root of the src folder.

    This file can have whatever name you prefer. We’re currently calling it deps.ts because it’s what is mentioned in Deno’s documentation, and it’s the naming convention many modules use.

  2. Move all the external dependencies from our code to deps.ts.

    Currently, the only dependency we have is the HTTP module from the standard library, which can be found in the src/web/index.ts file.

  3. Move the import into the deps.ts file and change import to export:

Get hands-on with 1200+ tech skills courses.