Use Node.js Module In A Titanium App?
Solution 1:
require('./lib/node_modules/ddp/lib/ddp-client.js');
It's very likely this module won't work for you. It has a lot of dependencies that use NodeJS specific modules, and specific APIs.
Luckily, someone has already written a module to connect to a Meteor server using DDP (I plead complete ignorance of this protocol and stack, by the way):
Solution 2:
You can use try this module https://github.com/smclab/titaniumifier
Get a Titanium™ SDK CommonJS module out of a Node package!
Solution 3:
Titanium now has partial support for npm modules: http://docs.appcelerator.com/platform/latest/#!/guide/Node.js_Support
For Alloy projects, do your npm install
commands in app/lib
so that your packages are stored in app/lib/node_modules
.
For non-alloy projects, do your npm
install in Resources/
so that your packages are stored in Resources/node_modules
.
Note that you may have problems with packages that rely on native node modules.
Solution 4:
sure, why can't?
here is an example using node module in Alloy project:
1.install q.js, which will create a folder named "node module" and contain some files :
$ npm install q
$ find node_module
node_modules/
node_modules/q
node_modules/q/README.md
node_modules/q/queue.js
node_modules/q/package.json
node_modules/q/q.js
node_modules/q/LICENSE
2.copy the q.js to your app/lib/ folder:
$ mkdir app/lib
$ cp node_modules/q/q.js app/lib
3.declare it in your Titanium file:
// in app/alloy.js
Q = require('q')
4.use it in your controller:
// app/controllers/index.js:
var defer = Q.defer();
Post a Comment for "Use Node.js Module In A Titanium App?"