nodejs: install package if not exists (windows version)?

Viewed 556

In my script I have

const mysql = require('mysql');

Is there a way to install mysql in runtime (if not installed yet) ? I read this solution: Is it possible to install npm package only if it has not been already installed?

But this is done through shell and not applicable in windows I look for a windows version.

My goal is to provide scripts to my client - he is unable to lunch some npm commands to install packages.

1 Answers
npm list mysql || npm install mysql

npm list <package> will return └── (empty) (Node.js v10.15.3) if package does not exist.

Related