Fetch packages from npm for Security purposes
npm install @nodesecure/npm-security-fetcher
a Node.js CLI created to simplify the analysis of npm registry packages.
bash
$ npm i npm-security-fetcher -g
`
or
`bash
$ git clone https://github.com/fraxken/npm-security-fetcher.git
$ cd npm-security-fetcher
$ npm ci
$ npm link
`
Then the nsf binary will be available in your terminal.
`bash
$ nsf --help
`
Usage example
The first step is to create a javascript file with three methods:
- init (run before fetching and extracting packages from the npm registry).
- run (called for each downloaded npm packages).
- close (run at the end when there is no more packages to fetch).
This script must use the latest Node.js ESM (it also support top-level-await).
`js
import path from "path";
export async function init() {
const baseDir = path.join(process.cwd(), "results");
return { baseDir }; // <-- init and return context object!
}
export async function close(ctx) {
console.log("close triggered");
}
export async function run(ctx, { name, location, root }) {
console.log(ctx.baseDir);
console.log(handle package name: ${name}, location: ${location});
}
`
> There is no restriction on the nature of the context.
After editing your file you can run your script as follows
`bash
$ nsf npm myfile.js
``
Gentilhomme 💻 📖 👀 🛡️ 🐛 |
Nicolas Hallaert 📖 |
WildCöde 💻 |
Kouadio Fabrice Nguessan 🚧 |