Install, remove and check existence of node_modules
npm install -S nommer
import { nmExists, nmInstall, nmRemove } from 'nommer'
Check whether node_modules exist at (or one directory below) specified path
import { nmExists } from 'nommer'
(async () => {
await nmExists()
// --> null
await nmExists("/right/path/containing")
// --> true
await nmExists("/right/path/containing/node_modules")
// --> true
await nmExists("/wrong/path/")
// --> false
await nmExists("/wrong/path/node_modules")
// --> false
})()
Run
npm install
in specified directory
import { nmInstall } from 'nommer'
(async () => {
await nmInstall()
// --> null; does nothing
await nmInstall(process.cwd())
// --> true; run npm install in cwd
await nmInstall("right/path/to/child/module")
// --> true; run npm install in child module
})
rm -Rf
node_modules with some protection
Protection
- Is this a
node_modules
directory? If not, stop. - Is this the current working directory? If so, stop.
import { nmRemove } from 'nommer'
(async () => {
await nmRemove()
// --> null; does nothing
await nmRemove(process.cwd())
// --> console warning: cannot remove cwd
await nmRemove("right/path/containing/node_modules")
// --> true; removes modules
await nmRemove("right/path/containing")
// --> true; removes modules
await nmRemove("wrong/path/")
// --> false; does nothing
await nmRemove("wrong/path/containing/node_modules")
// --> false; does nothing
})