View async-function-rejection.js
async function example() {
// you can catch rejected promises that you await on
try {
await Promise.reject('blargh');
} catch (err) {
console.log(err);
}
// if you don't catch, then `example()` resolves to a rejected promise
await Promise.reject('blah')
View gist:7285d7cfc38248b813f7cd34b77647e6
async function awaitsRejectection() {
await Promise.reject('blah');
}
async function throwsStuff() {
throw new Error('blah');
}
View gist:8766e645512c6ba15bdba9d9e8cbb98a
async function awaitsRejectection() {
await Promise.reject('blah');
}
async function throwsStuff() {
throw new Error('blah');
}
View enum.js
function Enum(names) {
let members = Object.create(null);
members.tryParse = name => {
if (!members[name]) {
throw new Error(`Unable to parse '${name}' as an Enum member.`);
}
return members[name];
};
View keybase.md

Keybase proof

I hereby claim:

  • I am jmar777 on github.
  • I am jmar777 (https://keybase.io/jmar777) on keybase.
  • I have a public key whose fingerprint is 5159 0463 0A5F 35F7 0ECC B9FB B5AB 0119 5DC6 FB5E

To claim this, I am signing this object:

View dw-node-http-request-example.js
function getTestPersonaLoginCredentials(cb) {
http.get({
host: 'personatestuser.org',
path: '/email'
}, function(res) {
// explicitly treat incoming data as utf8 (avoids issues with multi-byte chars)
res.setEncoding('utf8');
// incrementally capture the incoming response body
View debugging-node-elastic-beanstalk-woes
First, we need to figure out what the actual error is. This is obviously frustrating given that the error message is intentionally truncating it.
1) SSH in to your node (various guides available for this if you're not already familiar with this).
2) Run this command (basically an Elastic Beanstalk wrapper command for npm install I found in a blog post [1]):
$ sudo /opt/elasticbeanstalk/containerfiles/ebnode.py --action npm-install 2
3) Find the actual error message in the output from the npm install.
Once you know the error, it should hopefully be fairly obvious how to fix it. I've run into two different errors over the last couple days on Elastic Beanstalk:
The first was a dependency that was using the new "^X.Y.Z" version syntax, which is only supported in Node >= v0.10.26 (whereas Elastic Beanstalk only supports up to v0.10.21 as of today). The solution here was easy: hardcode a dependency version *prior* to when that dependency adopted to the new syntax.
View index.js
var db = connect('localhost:27017/aggr-test');
print('Dropping indexes...');
db.events.dropIndexes();
print('Creating index...');
var indexStart = Date.now();
db.events.ensureIndex({ ts: 1 });
var indexDuration = ((Date.now() - indexStart) / 1000).toFixed(2);
print('Index created (' + indexDuration + ' seconds)');
View gist:1571615
jmar777:gaas-license-verification jeremymartin$ jitsu deploy
info: Welcome to Nodejitsu
info: It worked if it ends with Nodejitsu ok
info: Executing command deploy
info: Authenticated as jmar777
info: Analyzing your application dependencies in app.js
warn: Local version appears to be old.
warn: Your package.json version will be incremented for you automatically.
warn: About to write /Users/jeremymartin/Projects/gaas-license-verification/package.json
data:
View gist:1571603
jmar777:gaas-license-verification jeremymartin$ jitsu create
info: Welcome to Nodejitsu
info: It worked if it ends with Nodejitsu ok
info: Executing command create
info: Authenticated as jmar777
warn:
warn: Your package.json file is missing required fields:
warn:
warn: scripts.start
warn: