DailyJS

DailyJS

The JavaScript blog.


Tagnode
Featured

modules events conferences iojs libraries node npm

Node Roundup: 0.12.5, 0.10.39, io.js 2.3.1, NodeDay, Apey Eye

Posted on .

Node 0.12.5, 0.10.39, io.js 2.3.1

Two new releases of Node just came out. Both releases fix OpenSSL security issues, but 0.12.5 also includes updates for uv and npm.

io.js 2.3.1 was also released this week. One of the big changes in this release is performance improvements for require:

module: The number of syscalls made during a require() have been significantly reduced again (see #1801 from v2.2.0 for previous work), which should lead to a performance improvement (Pierre Inglebert) #1920.

This sounds very nice for large projects.

NodeDay

NodeDay

NodeDay is a conference being held in London on 26th June (this Friday), for free! Speakers include Lin Clark, who writes npm's excellent blog posts, and programmers from the BBC, Red Hat, and other companies that are using Node for interesting things.

nodeday is a Node.js conference by the enterprise, for the enterprise. Now in its second year, this one-day industry conference brings together people from companies that have adopted or are planning to adopt Node.js, and focuses on the issues that these companies face. It gives participants a forum to discuss and share their experiences with Node.js, share advice, tips and tricks, and drive forward both the technology and the community.

I apologise for not writing about this sooner, but I only just found out about it! If you have conferences you want me to cover on DailyJS, you can use the contact forms or message me on Twitter (@alex_young).

I really wanted to go to NodeDay but I can't make it this time.

Apey Eye

Filipe Sousa sent in Apey Eye (GitHub: https://github.com/glazedSolutions/apey-eye, License: MIT, npm: apey-eye):

Apey Eye is an Object-Resource Mapping Node.js API framework that uses next-generation JavaScript features that can be used today, like Classes, Decorators and async/await for maximum expressiveness.

This is a framework for building data layers that map directly to REST APIs. It's a bit like ORM for HTTP. It comes with base classes for routing, REST resources, models, and validation, and the models can serialise data to RethinkDB. To talk to other databases a new base model class would have to be written.

Thanks to ES6, the model syntax is very clean:

let Model = ApeyEye.Model;

class MyModel extends Model {  
    constructor() {
        super(async function() { (...) });
    }

    static async fetch() { (...) }
    static async fetchOne() { (...) }
    async put() { (...) }
    async patch() { (...) }
    async delete() { (...) }
}

To me this looks like C# without the extra syntax for strong typing. The validation API looks similar to what you might have seen before with modules like Mongoose.

I like the idea of object-resource mapping at the HTTP level. In Node web apps we seem to spend a lot of time thinking about HTTP servers and APIs, so this feels like it could reduce the amount of boilerplate required to interface from that step to the database layer.

Featured

node command-line servers libraries

Add a CLI to Node Apps with Vantage

Posted on .

Vantage (GitHub: dthree/vantage, License: MIT, npm: vantage) by David Caccavella is a very nicely packaged module for adding command-line interfaces to your Node applications. It provides two components: a server, and a command-line tool that you use to connect to your live app. Rather than connecting to a TCP port with something like telnet, you actually type vantage in the command-line.

To hook it up to your application, you'll need to add a Vantage server. First, install Vantage to your project (npm install --save vantage), then instantiate a Vantage object and hook up the functionality that you want:

var Vantage = require('vantage');  
var server = new Vantage();

server  
  .command('foo')
  .description('Outputs "bar".')
  .action(function(args, cb) {
    // Do anything: check the database, run migrations, show useful stats
    console.log('bar');
    cb();
  });

server  
  .delimiter('webapp~$')
  .listen(80)
  .show();

I'd put this in a separate file to your main Express/Koa/Hapi/etc. app server, then add Vantage actions for the desired functionality. You could add things like database queries, or heartbeat/usage info, and so on.

Once you've added Vantage to your web app, if you install it globally you'll be able to just type vantage ip:port to connect to your server. Typing help will display the built-in commands and any actions that you've added. You should see something like this for the previous example:

webapp~$ help

  Commands

    help [command]    Provides help for a given command.
    exit [options]    Exists instance of Vantage.
    vantage [server]  Connects to another application running vantage.
    foo               Outputs "bar".

In addition to basic commands and subcommands, Vantage uses inquirer for prompts. Inquirer's prompts are quite powerful: they're ideal for things like yes/no questions and checkboxes. You could use it to force a "yes/no" prompt before a irreversible operation.

Vantage has a few other nice features that'll make your backdoor feel more professional: you can add a banner when people sign in (perhaps with legal warnings, or help), it supports a "firewall" for limiting access, and the documentation has details for using Vantage with Express, Koa, and TLS/SSL.

On the subject of backdoors: Vantage doesn't currently support authentication. It may be possible to use it as a limited informational interface to your server, but I'd strongly recommend binding to internal interfaces only. That means you'd have to ssh to a server, and then run vantage remotely. If that's not possible or convenient, then at least set up TLS/SSL. The current idea for authentication is to support it through middleware -- it already supports middleware so actions can be made reusable, so it seems like a sensible approach.

Authentication issues aside, it definitely seems like something worth using for development servers: I know many people who would love to see their Node web apps get the kind of consoles that popular web frameworks offer (Django's manage.py shell and Rails' console are two that spring to mind). Check it out, but try local/development mode first!

Featured

node iojs

Node.js Foundation: New Members, Technical Governance

Posted on .

After io.js joined the Node Foundation, there's now the news that the industry backers and developer communities behind the Node.js Foundation are working together to ratify the "open governance structure":

The open, technical governance model that will guide the project was determined with input from the public, including contributors from both the Node.js and io.js communities. The model includes a Technical Steering Committee that will direct technical decisions, oversee working group projects and manage contributions to the node code base, and a Board of Directors to guide business decisions.

Joyent's CEO, Scott Hammond, wrote a blog post that ties in with the announcement:

There's a lot of work ahead to secure a successful future for Node.js. While crucial, an open governance model by itself does not guarantee long-term success. We'll need to balance the needs of the strong developer community with those of the users and encourage a vibrant ecosystem of technology and service providers to ensure the bright future we all envision. And the best way to strike this balance is through a community-driven, neutral foundation.

The PR behind all of this has been much more professional than what I've previously seen from Node, so I'm still cautiously optimistic about the development of the Foundation and its implications for us, as JavaScript programmers. The industrial backing is impressive:

Founding and new members include Platinum members Famous, IBM, Intel, Joyent, Microsoft and PayPal. Gold members include GoDaddy, NodeSource and Progress Software, and Silver members include Codefresh, DigitalOcean, Fidelity, Groupon, nearForm, npm, Sauce Labs, SAP, StrongLoop and YLD!.

But what about The Great Merge of 2015? The press release does say that the "Node.js and io.js developer communities today are announcing a collaboration to merge their respective code bases" – but I'm still not clear about when and how this is happening.

Meanwhile, io.js 2.3.0 is out, and Node is still at 0.12.4 (stable). If you're invested in Node my advice is to keep following io.js releases closely. I still see a lot of apps running 0.10.x in production. If you're at the latest security patched version then I wouldn't worry too much about switching over to io.js just yet. However, there's no harm in having a branch in your project that runs unit tests against io.js.

Featured

resources hardware libraries node browser

Myo.js, JavaScript.com

Posted on .

Myo.js

Myo

Myo from Thalmic Labs is a gesture control armband that's described as a "wearable presentation remote". Paul Bernhardt from Thalmic Labs sent me myo.js (GitHub: thalmiclabs/myo.js, License: BSD 3-Clause, npm: myo), a JavaScript library for interacting with the device. It uses WebSockets to talk to Myo Connect, which runs on your desktop.

The API is based around events. Here's a quick example:

myMyo.on('gyroscope', function(data) {  
  if (data.x > 100){
    alert('Woah now!')
  }
});

It also supports "poses", for example: myMyo.on('thumb_to_pinky', cb).

The API is pretty well documented, with method documentation and examples in the readme. There's also a blog post that introduces Myo.js.

JavaScript.com

JavaScript.com

Code School, the web-based subscription tutorial site, has recently launched javascript.com. It has an interactive tutorial, a blog, and resources to help beginners.

Naturally it promotes Code School (owned by Pluralsight), but it's nice to see something useful and well designed there. It used to have a very dated internet.com page, so Code School's page is a step up.

Featured

apps realtime servers node

A Server for Realtime Apps: deepstream.io

Posted on .

deepstream.io

Wolfram Hempel sent in an open source server called deepstream.io (GitHub: hoxton-one/deepstream.io, License: MIT, npm: deepstream.io). Deepstream is a Node server that allows clients to sync data, whether they're browsers or mobile applications. It has a caching layer, and supports event-based messaging and RPC.

If you install deepstream.io with npm, you can create a simple server like this:

var DeepstreamServer = require( 'deepstream.io' );  
var server = new DeepstreamServer();

server.set('host', 'localhost');  
server.set('port', 6020);

server.start();  

Then in the browser you can connect with var ds = deepstream('localhost:6020').login(). The ds object can be used to fetch and set data. The tutorial shows how to do this with a simple HTML form:

var record = ds.record.getRecord('someUser');  
var input = document.querySelector('input');

input.onkeyup = function() {  
  record.set('firstname', input.value ;
};

record.subscribe('firstname', function(value) {  
  input.value = value;
});

The RPC calls allow functions to be bound to function names. One nice property of RPC in deepstream is if multiple clients are able to provide the same RPC, it will distribute requests evently between them.

The project is still new, but there are a good amount of tutorials already, including React and Angular examples.