Open In App

How to Add Third Party Library Deno.js ?

Last Updated : 17 Jan, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

Today we will learn how to add your own module to Deno.js for usage by the users. As we know there are standard modules added in any language or environment. Similarly in Deno.js a number of inbuilt/standard modules are available for a user.

Adding a new module to a language or an environment helps one in a number of ways- One learns how to contribute to open source and also to write the tested modules and scripts so that the users can use them in the best possible way.

Prerequisite:

  • Familiar with JavaScript or TypeScript
  • Install Deno.js on the machine. (Confirm by typing deno -v in the command line).
  • Familiar with GitHub and how to pull, and fork a Repository.

Code Structure:

To get started with the code structure for adding a module to Deno.js one needs to follow a particular file structure.

git clone https://github.com/guptamohit004/ip_details
cd ip_details

This is one of the modules added by me. One needs to follow the same pattern for adding the module to DENO.

So let’s see the code structure and understand what you need to do.

  • MOD.ts – It is usually the entry point of any module. One needs to write the main function/code in this file. It is similar to index.js/app.js in Node.js.
  • CLI.ts – It is the file that would be executed when one uses the module from CLI. Here you can define what all arguments need to be passed while executing the script.
  • MOD_TEST.TS – It is the file that is used during development and used to test the module from CLI. In this standard Library, Deno is used to getting the functions of testing in Deno.
  • README.MD – It is the file that gives the viewer/user all the information related to the module like how the module is to be used, what will be requested and what will be the response, and how to use the module in different situations like CLI, Importing from a module, bash, etc. One needs to add this image of testing all the cases for getting the module available from the Deno website. 
  • Important – One needs to add all configuration/permissions in this file such as –allow-net, –allow-read, –allow-write.

Where is PACKAGE.JSON?

As we know that while developing a module using Node.js, we need to have a Package.json file in the code folder. But in the case of using Deno, one doesn’t need to have such a file and can directly use the modules from the URL and store them in the computer cache.

Now start Building your module and run and test it from CLI as well as using the test command.

Now comes the Publishing part-

  • Add your module to your GitHub and enable the actions from your repo.
  • Make the repo public.
  • Now go to DATABASE.JSON.
  • Add your module details in the following format.
"my_library_name": {
"type": "github",
"owner": "",
"repo": ""
}zo
  • Now create a pull request to update the file.
  • Write “Add `your_module_name` to Deno.
  • Make Pull Request.
  • Now your updated file needs to pass some tests and you are good to go.
  • Successfully created a pull request. Wait for the approval.

Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads