The JavaScript blog.


mobile node modules npm mongo generators libraires

Orientation and Vibration APIs, Mongomery

Posted on .

Orientation and Vibration APIs for Games

Andrzej Mazur sent in an article about using the orientation and vibration APIs for game development:

The Device Orientation API specification is still in the Working Draft status, so there might be some code-breaking changes introduced in the future. It's an experimental technology and should be treated as such. All implementations are still missing the compassneedscalibration event. Also, there are differences in browser implementations which should be taken into consideration. For instance, Chrome and Opera don't support the devicemotion event.

The Vibration API is another feature that can boost the mobile experience. Most devices support it (except iOS Safari and Opera Mini), and it works great on Firefox OS devices.

I've never used the vibration API, but apparently you can access it with window.navigator.vibrate. It even supports an array of values for vibrating multiple times. Andrzej's argument is that you can use these APIs to differentiate your game from other mobile web games, and while this is true it'll take a fair bit of experimentation to get orientation-based controls working well!


Coderaiser has sent in a few generator-based modules recently, but I missed Mongomery (GitHub: coderaiser/node-mongomery, License: MIT, npm: mongomery), a module that uses generators for MongoDB. It uses ruff, which was Coderaiser's module for giving generators a more EventEmitter-inspired API:

var mongomery = require('mongomery');

mongomery(function*(mongo) {  
  var url = 'mongodb://localhost:27017/myproject',
  var db = yield mongo.connect(url),
  var collection = db.collection('mongolog'),
  var docs = yield collection.find({}).toArray();

  docs.forEach(function(item) {

}).on('error', function(error) {

It'll take us a few years to really understand how new features like generators should be used in terms of databases, but I'm very interested in using generator syntax for databases.

An alternative that I've enjoyed experimenting with is Mongorito, which is more of an ODM-style API. The syntax is more succinct than Mongoose, while still remaining familiar.


mobile modules npm touchscreen

Interdimensional, Package Quality

Posted on .


Interdimensional (GitHub: vodkabears/Interdimensional, License: MIT, npm: interdimensional, Bower: interdimensional) by Ilya Makarov is a library for responding to gyroscope events on devices that support the deviceorientation event. The demo site will start responding to tilts when you tap the polygon icon at the bottom-left of the screen.

The library's behaviour can be tweaked by changing the PPD option (pixels per difference between tilts), and there's also an insensitivity option for the minimum difference between tilts.

To start using spatial scrolling, call Interdimensional.charge. The library will emit events on the document object, so you can detect when the feature is enabled (interdimensional:charge), and if it wasn't possible to enable it (interdimensional:fail).

Package Quality

Package Quality

Package Quality by Alex Fernández is a service that evaluates npm packages based on npm and GitHub metrics. It's ideal if you want to quickly compare several competing packages.

The source is on GitHub (alexfernandez/package-quality) and the project is written with Express and MongoDB. The readme for the project has more details about how package quality is determined. The authors admit that any such measurements are potentially problematic, but they explain how version, downloads, and repo quality is measured so you can see what the numbers really mean.


libraries mobile node modules security sms

Node Roundup: no-sequence, CodeOnMobile, app-notify

Posted on .


If you've got a corporate policy for enforcing strong passwords, then you might want to look at what npm modules can help validate passwords rather than rolling your own. Eric Douglas sent in no-sequence (GitHub: thothJS/no-sequence, which checks to ensure passwords do not contain sequential characters:

var noSequence = require('no-sequence').checkSequence;  
var assert = require('assert');  
var password = '123456';  
var minSize = 6;

assert.equal(noSequence(password, minSize), false);  

The repository has examples and tests which show it working with character sequences and minimum and maximum sizes.


Daishi Kato has been working on a new project that allows you to write code on phones and tablets. He notes that this is good for holiday hacking, when you're stranded without a desktop/laptop.


It works with GitHub accounts, and there's a live demo here: codeonmobile.axlight.com. The source is available at GitHub under dai-shi/codeonmobile with a BSD license, and uses Codeship to deploy your app to Heroku.


app-notify (GitHub: chovy/app-notify, License: ISC, npm: app-notify) by Anthony Ettinger is a module for sending SMS messages. You can use promises, or callbacks:

  message: 'Hello world'

It requires Twilio credentials for SMS, and can also send email (with nodemailer).


performance mobile backbone

Linting Backbone Apps, Hybrid Mobile Performance

Posted on .


eslint-plugin-backbone (GitHub: ilyavolodin / eslint-plugin-backbone, License: MIT, npm: eslint-plugin-backbone) by Ilya Volodin is a Backbone-specific ESLint plugin. It can verify collections and views, which will help you find common mistakes like direct jQuery usage inside views.

Each of the rules is documented, and the documentation describes when not to use the rule as well. This is good if you're hitting a lot of linter errors for specialised behaviour that should be ignored.

Because the rules are so well documented you might like to use it to brush up on your Backbone best practices as well.

Hybrid Mobile Performance with browser-perf

If you're developing cross-platform apps powered by technologies like Cordova, how do you benchmark them? browser-perf by Parashuram is a Node module for gathering rendering performance metrics. The author has recently published a blog post called Cordova Apps - Rendering Performance that describes how to use browser-perf with hybrid mobile apps.

When developing a mobile app, one of the concerns of using the Hybrid approach is performance. Achieving smooth experience like a native app is important for Hybrid apps and developer tools for Android and iOS have been helping to a great deal.

For Android, Chromedriver is used with the Selenium JSON wire protocol. iOS uses Appium, but Parashuram had to enable performance logs before this worked.


libraries mobile modules responsive

RWDPerf, respimage

Posted on .


RWDPerf report

RWDPerf (GitHub: lafikl / RWDPerf, License: MIT, npm: rwdperf) by Khalid Lafi is a tool for analysing responsive pages. It calculates the page weight, so you can see what the download bloat is like.

It works using Chrome's remote debugging API, so it should be more accurate than a DOM simulation. It accepts arguments on the command-line for configuring things like device scale factor, width, height, and user agent.

It also has an API, which is ideal for dropping it into a build script.


If RWDPerf indicates that your page has a lot of unused images, then you might want a better responsive image replacement library. Respimage (GitHub: aFarkas / respimage, License: MIT) by Alexander Farkas is a responsive image polyfill for picture and srcset.

Respimage works using the picture element or the srcset image attribute. The srcset implementation supports descriptors for width and density.

There's also a JavaScript API, so you can also support dynamically generated content.