DEV Community

Rocktim Saikia
Rocktim Saikia

Posted on

3 2

✨ read-packages : a simple package that returns the dependencies of a package.json file.

I wrote a simple module that returns the dependencies of a package.json file.

It has some additional options that you can pass in. Check the project readme for more info.

Installation

npm install read-packages
Enter fullscreen mode Exit fullscreen mode

Usage

const readPackages = require('read-packages');

(async()=>{
       console.log(await readPackages());
       //=> {dependencies: {foo: '^1.0.0',..}, devDependencies: {bar: '^2.0.0',...}}

       console.log(await readPackages({dir: './some/other/directory'}));
       //=> {dependencies: {...}, devDependencies: {...}}

       console.log(await readPackages({removePrefix: true}));
       //=> {dependencies: {foo: '1.0.0',..}, devDependencies: {bar: '2.0.0',...}}

       console.log(await readPackages({removePrefix: true, flattenPackages: true}));
       //=> {foo: '1.0.0',bar: '2.0.0',...}
})();
Enter fullscreen mode Exit fullscreen mode

GitHub logo rocktimsaikia / read-packages

Read dependencies of a package.json file.

read-packages build license

Read dependencies of a package.json file.

Install

npm install read-packages
Enter fullscreen mode Exit fullscreen mode

Usage

const readPackages = require('read-packages');

(async()=>{
        console.log(await readPackages());
        //=> {dependencies: {foo: '^1.0.0',..}, devDependencies: {bar: '^2.0.0',...}}

        console.log(await readPackages({dir: './some/other/directory'}));
        //=> {dependencies: {...}, devDependencies: {...}}

        console.log(await readPackages({removePrefix: true}));
        //=> {dependencies: {foo: '1.0.0',..}, devDependencies: {bar: '2.0.0',...}}

        console.log(await readPackages({removePrefix: true, flattenPackages: true}));
        //=> {foo: '1.0.0',bar: '2.0.0',...}
})();
Enter fullscreen mode Exit fullscreen mode

Usage without async

The module has a sync property to use the lib without async. All the other options works just the same.

const readPackages = require('read-packages');
console.log(readPackages.
Enter fullscreen mode Exit fullscreen mode

[PS: Thought someone might find it a handy tool so I made a quick post. Thanks for reading 🦄 👋]

Reinvent your career. Join DEV.

It takes one minute and is worth it for your career.

Get started

Top comments (2)

Collapse
 
rajasekharguptha profile image
Rajasekhar Guptha

Cool😍

Collapse
 
rocktimsaikia profile image
Rocktim Saikia

Thank you 🙏

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay