Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js - Can I install NPM package on a PhoneGap / Cordova application?

I'm building a mobile app thanks to Cordova, and as Cordova is based on Node.js, I thought that I could use NPM packages into the app.

For example, I want my mobile app to talk to a remote MySQL database. I thought I could use the mysql NPM package (https://www.npmjs.org/package/mysql) in order to embed a MySQL driver into my mobile app, but I don't see any docs or tutos to install NPM packages into my mobile app.

So, is that possible to "embed" NPM packages into a Cordova app ? Is my app "architecture" bad ?

Thanks a lot for your help.

Regards, Sylvain

like image 341
SylvainLap Avatar asked Oct 31 '22 20:10

SylvainLap


1 Answers

You can use node packages for development purposes like using grunt, bower, etc. but inside the app you have to use phonegap/cordova plugins.

You cannot use node modules in your phonegap app, because even if they are js files they require the Node.JS runtime to work and you cannot install or embed NodeJS on the mobile platforms.

But you can use any JS library that doesn´t not have a Node dependency, some I have used are moment.js, knockout.js, jquery, backbone.

Hope it helps.

like image 92
Carlos487 Avatar answered Nov 11 '22 06:11

Carlos487