How to properly export an ES6 class in Node 4?

If you are using ES6 in Node 4, you cannot use ES6 module syntax without a transpiler, but CommonJS modules (Node’s standard modules) work the same. should be hence the error message “Cannot set property ‘AspectType’ of undefined” because module.export === undefined. Also, for can you just write and get essentially the same behavior.

Push items into mongo array via mongoose

Assuming, var friend = { firstName: ‘Harry’, lastName: ‘Potter’ }; There are two options you have: Update the model in-memory, and save (plain javascript array.push): or I always try and go for the first option when possible, because it’ll respect more of the benefits that mongoose gives you (hooks, validation, etc.). However, if you are doing … Read more

Node update a specific package

Most of the time you can just npm update (or pnpm update or yarn upgrade) a module to get the latest non breaking changes (respecting the semver specified in your package.json) (<– read that last part again). Use [p]npm|yarn outdated to see which modules have newer versions Use [p]npm update|yarn upgrade (without a package name) to update all modules Major version upgrades: In your case, it … Read more

XMLHttpRequest module not defined/found

XMLHttpRequest is a built-in object in web browsers. It is not distributed with Node. The http module is the built-in tool for making HTTP requests from Node. Most people making HTTP requests from node use a third party library with a friendlier API. Two popular choices are Axios (for use both in Node.js and browsers) and node-fetch (which implements the fetch API … Read more

node.js TypeError: path must be absolute or specify root to res.sendFile [failed to parse JSON]

The error is pretty clear, you need to specify an absolute (instead of relative) path and/or set root in the config object for res.sendFile(). Examples: or specify a root (which is used as the base path for the first argument to res.sendFile(): Specifying the root path is more useful when you’re passing a user-generated file path which could potentially contain malformed/malicious … Read more

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