How to Add Third Party Library Deno.js ?
Today we will learn how to add your own module to deno.js for usage by the users. As we know that 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.
- 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
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.
- 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.
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses
are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!