How can I uninstall npm modules in Node.js?

The command is simply npm uninstall <name> The Node.js documents https://npmjs.org/doc/ have all the commands that you need to know with npm. A local install will be in the node_modules/ directory of your application. This won’t affect the application if a module remains there with no references to it. If you’re removing a global package, … Read more

How do you get a list of the names of all files present in a directory in Node.js?

You can use the fs.readdir or fs.readdirSync methods. fs is included in Node.js core, so there’s no need to install anything. fs.readdir const testFolder=”./tests/”; const fs = require(‘fs’); fs.readdir(testFolder, (err, files) => { files.forEach(file => { console.log(file); }); }); fs.readdirSync const testFolder=”./tests/”; const fs = require(‘fs’); fs.readdirSync(testFolder).forEach(file => { console.log(file); }); The difference between the … Read more

map function for objects (instead of arrays)

There is no native map to the Object object, but how about this: var myObject = { ‘a’: 1, ‘b’: 2, ‘c’: 3 }; Object.keys(myObject).forEach(function(key, index) { myObject[key] *= 2; }); console.log(myObject); // => { ‘a’: 2, ‘b’: 4, ‘c’: 6 } But you could easily iterate over an object using for … in: var … Read more

How do I completely uninstall Node.js, and reinstall from beginning (Mac OS X)

Apparently, there was a /Users/myusername/local folder that contained a include with node and lib with node and node_modules. How and why this was created instead of in my /usr/local folder, I do not know. Deleting these local references fixed the phantom v0.6.1-pre. If anyone has an explanation, I’ll choose that as the correct answer. EDIT: … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)