Is there any way to not return something using CoffeeScript?

You have to explicitly return nothing, or to leave an expression evaluating to undefined at the bottom of your function: fun = -> doSomething() return Or: fun = -> doSomething() undefined This is what the doc recommends, when using comprehensions: Be careful that you’re not accidentally returning the results of the comprehension in these cases, … Read more

React input defaultValue doesn’t update with state

Another way of fixing this is by changing the key of the input. <input ref=”text” key={this.state.awayMessage ? ‘notLoadedYet’ : ‘loaded’} onChange={this.onTextChange} defaultValue={awayMessageText} /> Update: Since this get upvotes, I will have to say that you should properly have a disabled or readonly prop while the content is loading, so you don’t decrease the ux experience. … Read more

Can I determine if a string is a MongoDB ObjectID?

I found that the mongoose ObjectId validator works to validate valid objectIds but I found a few cases where invalid ids were considered valid. (eg: any 12 characters long string) var ObjectId = require(‘mongoose’).Types.ObjectId; ObjectId.isValid(‘microsoft123’); //true ObjectId.isValid(‘timtomtamted’); //true ObjectId.isValid(‘551137c2f9e1fac808a5f572’); //true What has been working for me is casting a string to an objectId and then … Read more

Uploading base64 encoded Image to Amazon S3 via Node.js

For people who are still struggling with this issue. Here is the approach I used with native aws-sdk : var AWS = require(‘aws-sdk’); AWS.config.loadFromPath(‘./s3_config.json’); var s3Bucket = new AWS.S3( { params: {Bucket: ‘myBucket’} } ); Inside your router method (ContentType should be set to the content type of the image file): var buf = Buffer.from(req.body.imageBinary.replace(/^data:image\/\w+;base64,/, … Read more

Null-safe property access (and conditional assignment) in ES6/2015

Update (2022-01-13): Seems people are still finding this, here’s the current story: Optional Chaining is in the specification now (ES2020) and supported by all modern browsers, more in the archived proposal: https://github.com/tc39/proposal-optional-chaining babel-preset-env: If you need to support older environments that don’t have it, this is probably what you want https://babeljs.io/docs/en/babel-preset-env Babel v7 Plugin: https://babeljs.io/docs/en/babel-plugin-proposal-optional-chaining … Read more