Node.js-我可以在PhoneGap/Cordova应用程序上安装NPM软件包吗? [英] Node.js - Can I install NPM package on a PhoneGap / Cordova application?

查看:83
本文介绍了Node.js-我可以在PhoneGap/Cordova应用程序上安装NPM软件包吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

感谢Cordova,我正在构建一个移动应用程序,并且由于Cordova基于Node.js,我认为我可以在该应用程序中使用NPM软件包.

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.

例如,我希望我的移动应用程序与远程MySQL数据库对话.我以为我可以使用mysql NPM软件包( https://www.npmjs.org/package/mysql)以便将MySQL驱动程序嵌入到我的移动应用程序中,但是我看不到任何文档或Tutos将NPM软件包安装到我的移动应用程序中.

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.

那么,是否可以将NPM软件包嵌入"到Cordova应用程序中?我的应用程序架构"不好吗?

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

非常感谢您的帮助.

关于, 西尔万

推荐答案

您可以将节点软件包用于开发目的,例如使用grunt,bower等.但是在应用程序内部,您必须使用phonegap/cordova插件.

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

您不能在phonegap应用程序中使用节点模块,因为即使它们是js文件,它们也需要Node.JS运行时才能运行,并且您无法在移动平台上安装或嵌入NodeJS.

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.

但是您可以使用任何不具有Node依赖项的JS库,我使用过的一些库是moment.js,knockout.js,jquery,b骨干.

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.

希望有帮助.

这篇关于Node.js-我可以在PhoneGap/Cordova应用程序上安装NPM软件包吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆