Folder structure for a Node.js project

Concerning the folders you mentioned: /libs is usually used for custom classes/functions/modules /vendor or /support contains 3rd party libraries (added as git sub-module when using git as source control) /spec contains specifications for BDD tests. /tests contains the unit-tests for an application (using a testing framework, see here) NOTE: both /vendor and /support are deprecated … Read more

Mongoose: findOneAndUpdate doesn’t return updated document

Why this happens? The default is to return the original, unaltered document. If you want the new, updated document to be returned you have to pass an additional argument: an object with the new property set to true. From the mongoose docs: Query#findOneAndUpdate Model.findOneAndUpdate(conditions, update, options, (error, doc) => { // error: any errors that … Read more

Declare multiple module.exports in Node.js

You can do something like: module.exports = { method: function() {}, otherMethod: function() {}, }; Or just: exports.method = function() {}; exports.otherMethod = function() {}; Then in the calling script: const myModule = require(‘./myModule.js’); const method = myModule.method; const otherMethod = myModule.otherMethod; // OR: const {method, otherMethod} = require(‘./myModule.js’);

Node.js throws “btoa is not defined” error

The ‘btoa-atob’ module does not export a programmatic interface, it only provides command line utilities. If you need to convert to Base64 you could do so using Buffer: console.log(Buffer.from(‘Hello World!’).toString(‘base64′)); Reverse (assuming the content you’re decoding is a utf8 string): console.log(Buffer.from(b64Encoded, ‘base64’).toString()); Note: prior to Node v4, use new Buffer rather than Buffer.from.

Node.js: what is ENOSPC error and how to solve?

Run the below command to avoid ENOSPC: echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p For Arch Linux add this line to /etc/sysctl.d/99-sysctl.conf: fs.inotify.max_user_watches=524288 Then execute: sysctl –system This will also persist across reboots. Technical Details Source

What is the “__v” field in Mongoose

From here: The versionKey is a property set on each document when first created by Mongoose. This keys value contains the internal revision of the document. The name of this document property is configurable. The default is __v. If this conflicts with your application you can configure as such: new Schema({..}, { versionKey: ‘_somethingElse’ })

How to completely remove node.js from Windows

How to remove Node.js from Windows: Take a deep breath. Run npm cache clean –force Uninstall from Programs & Features with the uninstaller. Reboot (or you probably can get away with killing all node-related processes from Task Manager). Look for these folders and remove them (and their contents) if any still exist. Depending on the … Read more

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