Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm install : specify package.json?

Tags:

node.js

npm

How can I tell npm to use another package.json when running "npm install" ?

All I need is npm install -f packages-win32.json Or is there a trick or another approach to achieve the same?

Because not all npm modules are cross-platform and I'd like to use other packages per platform.

like image 357
xamiro Avatar asked Nov 20 '15 12:11

xamiro


1 Answers

You cannot specify a different package.json file as the specs are literally only for a file called package.json.

If you have some issues with packages that only work on either os try them out with

try {
  thing = require('thing');
}
catch( error ) {
  thing = require('other');
}

You can also sniff out the os via:

const _isWin = /^win/.test( process.platform );

Or use os.platform() if you don't have to support node <= 5...

Maybe that helps?

like image 77
Dominik Avatar answered Sep 22 '22 06:09

Dominik