Tuesday, August 23, 2022

npm packages list in terminal

node -v

sudo apt install npm

npm list -g --depth 0 // list globally installed packages

npm list // list all packages installed in pwd

touch npm_globals.txt

nano touch npm_globals.txt

eslint@8.22.0

live-server@1.2.2

node-sass@7.0.1

npm-run-all@4.1.5

< npm_globals.txt xargs npm install -g


const { execSync } = require('child_process');
const fs = require('fs');

const package = JSON.parse(fs.readFileSync('package.json'));

let keys = Object.keys(package.dependencies);
let values = Object.values(package.dependencies);


for (let index = 0; index < keys.length; index++) {
    const key = keys[index];
    let value = values[index].replace("~", "").replace("^", "");

    console.log(`Installing: ${key}@${value} globally`,);
    execSync('npm i -g ' + `${key}@${value}`);
}

No comments:

Post a Comment