1

Currently I am writing a small Titanium app for testing. I need to include a module from NPM to titanium.

In this case I am trying with https://github.com/oortcloud/node-ddp-client

I am having the error saying Titanium couldn't find module.

The code I used for include is

var DDPClient = require("./lib/node_modules/ddp");

Can I use node.js modules in Titanium?

Thank you

4 Answers 4

2

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):

https://github.com/yubozhao/Ti.Meteor

Sign up to request clarification or add additional context in comments.

Comments

2

You can use try this module https://github.com/smclab/titaniumifier

Get a Titanium™ SDK CommonJS module out of a Node package!

1 Comment

Welcome. This answer is very brief, perhaps you could supply some more details such as an example?
2

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.

1 Comment

Do you know how to add native node modules?
0

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();

refer to: http://developer.appcelerator.com/question/154529/how-to-use-nodejs-modules-with-titanium#answer-285207

1 Comment

I have installed the node module and copied it into the project., But still didn't work. I have installed node module request.js and copied it to app/lib folder, now the build is throwing error, module not found - http.js, The module request .js is using http.js within itself, do i have to install all dependencies ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.