npm install is ran from your operating system prompt and not from inside mongosh. Once you install the package then you would run node <scriptname> from the command line, You need to make sure that the script has a valid connection string for your MongoDB instance in it for it to run.
Steeve mentions mjeneratejs in his post which is anohter NodeJS package that generates JSON data that could be imported into MongoDB.