3 examples of 'how to remove node modules' in JavaScript

Every line of 'how to remove node modules' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
111function cleanNodeModulePackages() {
112 return del(cleanGlobs);
113}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

186static _cleanModules(modules, pathToNodeModules) {
187 modules.forEach((p) => {
188 p.version = WebpackCdnPlugin.getVersionInNodeModules(p.name, pathToNodeModules);
189
190 if (!p.paths) {
191 p.paths = [];
192 }
193 if (p.path) {
194 p.paths.unshift(p.path);
195 p.path = undefined;
196 }
197 if (p.paths.length === 0 && !p.cssOnly) {
198 p.paths.push(
199 require
200 .resolve(p.name)
201 .match(/[\\/]node_modules[\\/].+?[\\/](.*)/)[1]
202 .replace(/\\/g, '/'),
203 );
204 }
205
206 if (!p.styles) {
207 p.styles = [];
208 }
209 if (p.style) {
210 p.styles.unshift(p.style);
211 p.style = undefined;
212 }
213 });
214}
34function cleanModulesIfVersionChanged(bosco, repoPath, repo, next) {
35 NodeRunner.getVersion(bosco, { cwd: repoPath }, function (err, currentVersion) {
36 if (err) { return next(err); }
37 var nodeVersionKey = 'teams:' + bosco.getTeam() + ':nodes:' + repo;
38 var lastVersion = bosco.config.get(nodeVersionKey);
39 if (lastVersion && lastVersion !== currentVersion) {
40 bosco.prompt.start();
41 var confirmationDescription = 'Node version in '.white + repo.cyan + ' has changed from '.white + lastVersion.green + ' to '.white + currentVersion.green + ', should I clear node_modules (y/N)?'.white;
42 bosco.prompt.get({
43 properties: {
44 confirm: {
45 description: confirmationDescription
46 }
47 }
48 }, function (err, result) {
49 if (!result || (result.confirm !== 'Y' && result.confirm !== 'y')) {
50 return next();
51 }
52
53 exec('rm -rf ./node_modules', { cwd: repoPath }, function (err, stdout, stderr) {
54 if (err) {
55 bosco.error('Failed to clear node_modules for ' + repoPath.blue + ' >> ' + stderr);
56 } else {
57 bosco.log('Node version in ' + repo.green + ' updated to ' + currentVersion.green);
58 bosco.config.set(nodeVersionKey, currentVersion);
59 }
60 next();
61 });
62 });
63 } else {
64 bosco.log('Node version in ' + repo.green + ' is OK at ' + currentVersion.green);
65 bosco.config.set(nodeVersionKey, currentVersion);
66 next();
67 }
68 });
69}

Related snippets