flexus-net
What and why?
This is (for now) just a simple wrapper module that makes lifes easier when installing Node.js net
module with JSPM for usage in browser-like app enviroments. Namely in Chrome packages apps and Windows modern apps.
Chrome provides quirky and overly complex chrome.sockets.tcp
API for TCP socket communication which is wrapped by wonderful module chrome-net
to provide the same API as Node.js net
.
And flexus-net
basically just wraps chrome-net
with intention to implement similar wrapper for Windows API in the future.
installation
jspm install npm:flexus-net
tips & tricks
You can rename the module from flexus-net
to net
in your JSPM config file and then use it simply as
import net from 'net';
or
var net = require('net');
Sweet. Now how to do it?
In JSPM config file there is property map
with names and mappings of all modules. This is an example of JSPM 0.17 jspm.config.js
map: {
"flexus-net": "npm:flexus-net@1.0.8",
"events": "github:jspm/nodelibs-events@0.2.0-alpha",
"process": "github:jspm/nodelibs-process@0.2.0-alpha",
...
where you change the name like so
map: {
"net": "npm:flexus-net@1.0.8",
...
Now you can write your app with net
module like you would in Node and JSPM handles picking the right module for given enviroment. When runnig in Chrome App the chrome-net
is used in background or when run in Node using JSPM run path_to_your.js
the native module is used.
thanks to
Feross Aboukhadijeh, John Hiesey & Jan Schä for creating chrome-net
and Guy Bedford for JSPM