Jeremy Martin jmar777

View debugging-node-elastic-beanstalk-woes
1 2 3 4 5 6 7 8 9 10
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
1 2 3 4 5 6 7 8 9 10
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
1 2 3 4 5 6 7 8 9 10
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
1 2 3 4 5 6 7 8 9 10
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:
View broken-makefile
1 2 3 4 5 6 7 8 9 10
.PHONY: clean install test test-tap test-api
 
clean:
rm ./test/results.tap
 
install:
npm install
 
test:
mocha -R list
View mocha-before-silent-error.js
1 2 3 4 5 6 7 8 9 10
describe('silent error', function() {
 
/*
// ReferenceError bubbles up just fine
before(function() {
assert('foo');
});
*/
 
/*
View app.js
1 2 3 4 5 6 7 8 9 10
var express = require('express'),
mongoose = require('mongoose'),
Model = require('./lib/model'),
Tap = Model.Tap;
 
app.post('/tap', function(req, res, next) {
var tap = new Tap();
tap.name = req.body.name;
tap.beer = req.body.beer;
tap.update({ name: tap.name }, { upsert: true }, function(err) {
View nodejs-max-recursion-error-message.js
1 2 3 4 5 6 7 8 9 10
/*
How do we provide more descriptive error messages for max-recursion situations?
*/
var depth = 0;
 
(function recurseBaby() {
// log at every 500 calls
(++depth % 500) || console.log(depth);
// bail out ~100K depth in case you're special and don't error out
View server-request-parsed-url.js
1 2 3 4 5 6 7 8 9
var _parsedUrl;
Object.defineProperty(req, 'parsedUrl', {
get: function() {
if (!_parsedUrl) {
_parsedUrl = url.parse(req.url, true);
}
return _parsedUrl;
}
});
View quick-micro-optimization-test.js
1 2 3 4 5 6 7 8 9 10
// dummy func
function noop() {}
 
// optimized via if/else
function testIfElse() {
var len = arguments.length;
if (len === 1) {
noop(arguments[0]);
} else if (len === 2) {
noop(arguments[1]);
Something went wrong with that request. Please try again.