First require, then run.
const npm_extractor = require('./path/to/node_modules_extractor.js')
...
let package_files = npm_extractor([
'baguetteBox.js',
'jquery',
'slick-carousel'
]);
Then do what you want with generated object:
// console.log(package_files);
{
main: [
'./node_modules/baguetteBox.js/dist/baguetteBox.min.js',
'./node_modules/jquery/dist/jquery.js',
'./node_modules/slick-carousel/slick/slick.js'
],
css: [
'./node_modules/baguetteBox.js/dist/baguetteBox.css',
'./node_modules/slick-carousel/slick/slick-theme.css',
'./node_modules/slick-carousel/slick/slick.css'
],
js: [
'./node_modules/baguetteBox.js/dist/baguetteBox.js',
'./node_modules/jquery/dist/core.js',
'./node_modules/jquery/dist/jquery.js',
'./node_modules/jquery/dist/jquery.slim.js',
'./node_modules/slick-carousel/slick/slick.js'
],
css_min: [
'./node_modules/baguetteBox.js/dist/baguetteBox.min.css'
],
js_min: [
'./node_modules/baguetteBox.js/dist/baguetteBox.min.js',
'./node_modules/jquery/dist/jquery.min.js',
'./node_modules/jquery/dist/jquery.slim.min.js',
'./node_modules/slick-carousel/slick/slick.min.js'
]
}