2
votes

Does anyone know the how to install and use npm packages in Alloy projects?

I am trying to use a sharepoint module, https://www.npmjs.com/package/sharepointconnector.

I have installed it via 'npm install sharepointconnector' in various directories, moved into /Resources, /app/lib directories, but still not working. Most cases I get the 'sharepointconnector not found in ...' error.

Any help is much appreciated.

2

2 Answers

1
votes

Appcelerator does not support npm packages to the alloy or classic app. Appcelerator only supports as a module, Titanium Module Concepts. Actually, that npm packages is created based on the nodeJS app. So, you can use that packages in your nodeJS app then create your custom API. Alloy or classic App support any web API.

Hope you got the point.

0
votes

In my own understanding, you can use any npm package that is not browser dependent.

Position your self in the folder myApplication/app/lib

(If you haven't created the lib folder yet, please do it inside the app folder)

Then install your npm package, lets take the validator package for example:

npm install validator

The trick in using the lib is to require it properly, you can't just call

var validator = require('validator');

if you go inside the lib folder you 'll find a node_modules/validator created with all its dependencies, inside you will find the file validator.js and that is the file i needed to require.

So what was left to do is correct the requiring call :

var validator = require("node_modules/validator/validator");
validator.isEmail("foo@bar.com") // returns true => happy days :)

Hope this helped