# Installing Node
Node.js is required for several Titanium SDK components, including the Titanium CLI and Alloy.
# Compatibility and download
Titanium supports and recommends the latest Node.js LTS release.
Check Titanium Compatibility Matrix which version of Node.js is required for each Titanium SDK version.
# Using NPM packages in Titanium
Run
npm initin theapp/libfolder in your Alloy project. If you are using a classic app, run the init step in your/Resourcesfolder.Follow the steps npm gives you when doing the init step. Note: You don’t have to fill out anything if you don't need to.
Execute
npm i <packagename>in the/libfolder to install a package. For example, let’s set up to.imagecache (opens new window). You'd use this comment to install the package:npm i to.imagecacheAdd the
lib/node_modulesfolder and thepackage-lock.jsonfile to your.gitignorefolder.On any other machine you want to set this up, go to your
/libfolder, runnpm installand all packages will be installed to your app.
# Usage of packages
Usage of a package is like another module or library file. Using the to.imagecache example:
var imageCache = require('to.imagecache');
# Dependencies
To install a package dependency,
Ensure you are in the
/libfolder, or if using a classic project, the/Resourcesfolder.Execute
npm i <dependency>To use the dependency, for example a module called
ImageViewfrom theto.cacheimageview(sample extension of theto.imagecachepackage):<ImageView id="myImage" module="to.cachedimageview" />
# Finding packages
To find all the current packages with the titanium-module, you can use this npm site search: https://www.npmjs.com/search?q=keywords:titanium-module (opens new window)
A lot of Titanium packages are found using the titanium or titanium-module keywords. Note: when creating a public common.js module and/or library file, please tag it with the titanium-module keyword.
# Troubleshooting
# Error: EONT, stat C:\Users\<USER_NAME>\AppData\Roaming\npm
The error message indicates the folder is missing. To resolve this issue, manually create the folder:
mkdir C:\Users\<USER_NAME>\AppData\Roaming\npm
# Issues installing NPM packages
If you experience an issue installing any of the npm packages, try the following:
Check permissions. If you originally ran
npmusingsudo, you may need to change the ownership of thenpmcache folder.sudo chown -R <username> ~/.npmrcOn Windows, the npm cache defaults to
npm-cachein the user's home folder.Clear the
npmpackage cache:npm cache cleanRemove your
.npmrcfile.