How can I update Node.js and NPM to their latest versions?

Use: npm update -g npm See the documentation for the update command: npm update [-g] [<pkg>…] This command will update all the packages listed to the latest version (specified by the tag config), respecting semver. Additionally, see the documentation on Node.js and NPM installation and Upgrading NPM. The following original answer is from the old … Read more

Node can’t find modules without .js extension

Node.js by default does not attempt to guess the file extension when using import for ES modules. This is different from CommonJS modules with require. In the documentation for the ES module loader you can read how files are found on disk. The heading ‘Customizing ESM specifier resolution algorithm’ states: The –experimental-specifier-resolution=[mode] flag can be … Read more

Can node modules require each other

Check out http://nodejs.org/api/modules.html#modules_cycles for how this is handled in node. You can solve your problem in several ways, for example passing in the dependencies to the instances aka Dependency Injection // user.js var User = function (Room) { this.Room = Room; }; User.prototype.test = function () { return new this.Room(); }; module.exports = User; // … Read more

Require dependency of another dependency in node modules

Do I just have to include mongoose as a dependency as well in the parent app or is there a way of getting access to that module by way of the child? While it’s possible for you to e.g. require(‘github/node_modules/mongoose’), the standard practice is to install all of your dependencies explicitly (i.e., you should include … Read more

Mixed default and named exports in Node with ES5 syntax

You want to assign the value of module.exports to be your default function, and then put all the named exports as properties on that function. const defaultFunction = () => { console.log(‘default!’); }; const namedFunction1 = () => { console.log(‘1!’); }; const namedFunction2 = () => { console.log(‘2!’); }; const myModule = module.exports = defaultFunction; … Read more

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