MetroNode
A Javascript Productivity Tool for WinStore/WinPhone apps

Introduction


MetroNode is a NuGet Plugin designed to integrate NodeJS/CommonJS into your WinStore/WinPhone apps without excessive developer effort. The tool supports hundreds of NodeJS modules, is compatible with popular javascript architectures and supports a variety of test tools.

Code like this:

// file: api.js
////////////////////////////
var async = require('async');
exports.processUsers = function(data, callback){
    var userNames = data.userNames;
    async.each(userNames,
        function(userName, userNameCallback){
            // Do some async work...
            return userNameCallback();
        },
        function(err){
            if(err)
                return callback(err);
            return callback();
        });
};

Can be used like this:

var app = WinJS.Application;
app.onactivated = function(args) {
    var userNames = ["Todd", "Kurt", "Tony"]; // list of user names
    MetroNode.api.processUsers({
        userNames: userNames
    },
    function(err){
        console.log("It Worked!");
    });
}

Compatibility:

Usage


Basic Setup


To get rolling, just go grab the bits from NuGet, include the MetroNode entry module into your index.htmland your all set.

Step 1:

Include the MetroNode package through NuGet:

Step 2:

Reference the MetroNode script in default.html:

<script src=".metro.node.js"></script>

Source Control


MetroNode uses some tricky cache files to integrate with MSBuild and also auto-generates a CommonJS entry module at build time. Ideally all of this cruft would be ignored in your solution.

Git:

echo '*.cache.js' >> .gitignore
echo '.metro.node.js' >> .gitignore

SVN:

svn propset svn:ignore "*.cache.js" .
svn propset svn:ignore ".metro.node.js" .

TFS:

echo '*.cache.js' >> .tfignore
echo '.metro.node.js' >> .tfignore

Mercurial:

echo '*.cache.js' >> .hgignore
echo '.metro.node.js' >> .hgignore

NPM Packages


You can reference compatible NPM Packages directly in your package.json, just like you would with standard NodeJS development.

Then the packages can be used with the require('module') convention or via a globally scoped MetroNode API.

Step 1:

Include the MetroNode package through NuGet:

Step 2:

Add the async npm package to the package.json:

{
        "name": "WinStoreApp",
        "version": "0.0.1",
        "dependencies": {
        "async": "0.9.0"
    }
}

Step 3:

Reference the MetroNode script in default.html:

<script src=".metro.node.js"></script>

Step 4:

Use the async package like this:

MetroNode.async
Full Sample:

var items = ['item1', 'item2', 'item3'];
MetroNode.async.each(items,
function(item, itemCallback){
	console.log(item);
	return itemCallback();
},
function(err){
	console.log(err);
});

Sweet Architectures


You can use the MetroNode library as a way to bootstrap your architecture by inner-mixing NodeJS/CommonJS modules.

MetroNode even auto-scaffolds your solution and creates friendly global APIs, just to make sure your code is highly accessible and always compatible for fair use.

Step 1:

Name NodeJS modules with extension *.node.js in Visual Studio:

helpers.node.js
/api
	index.node.js
	/models
		user.node.js
		account.node.js
	orm.node.js

Step 2:

Use custom modules as exported like this:

MetroNode.helpers.[export-methods]
MetroNode.api.index.[export-methods]
MetroNode.api.models.user.[export-methods]
MetroNode.api.models.account.[export-methods]
MetroNode.api.orm.[export-methods]

115 Supported Packages


Sponsored By: