简体   繁体   中英

possibility of using NodeJs server-side codes in mobile application?

Is that possible to use NodeJs server-side codes in react native,ionic,cordova or native script for mobile applications?

Question update: I want to use NodeJs package and include NodeJs package into mobile application ( native script , ionic , cordova or react native ). for example include instagram-private-api into native script : NodeJs Private instagram API

{N} !== Browser / NodeJS.

It's a pure JS runtime, any apis specific to these platforms won't work within {N}. Though nativescript-nodeify plugin on-boards very limited NodeJS apis by translating them to their native equivalents.

I've been using many node.js APIs (including google/baidu/bing/wikipedia) inside my cordova App, here's what I did:

  1. Install node.js / express / socket.io in your linux server.

  2. Use socket.io inside your Cordova app to create 'many clients to one server' connections between your app and the node.js/socket.io server. In https://socket.io there is a simple example teaching you how to do that.

  3. In Cordova App, use something like socket.emit('FromClientToServerCallAPI', data) to call an api.

  4. In node.js server, define a function:

socket.on('FromClientToServerCallAPI', data)

and inside this function, call your api, and after you got the result from the api provider, run:

socket.emit('FromServerToClientAPIResult', result)

  1. In your Cordova App, define a function:

socket.on('FromServerToClientAPIResult', result)

then do somthing with 'result'

pls. note that all the functions above are async.

Never try to call the api directly in your client codes, Some api provider requires you to apply for the api service and give you a 'key' to use the api, you don't want to put this 'key' inside your javacript and disclose it to all your users of the App, right?

Yes, it is possible with nodejs-mobile . It lets you run a full-blown Node.js engine inside a mobile application. It works on Android and iOS. There are other solutions that work on Android but as far as I know nodejs-mobile is currently the only one that also supports iOS. It also comes with plugins for React Native and Cordova.

More information, including documentation, is available on the project website.

(Full disclosure: I work for the company that develops nodejs-mobile.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM