Reputation: 11
I am trying to figure out how I can convert an existing express.js app into a mobile app using Apache Cordova. Currently, I can go into the root directory of my express app and run "node index.js", then I can view the current WebSite at http://localhost. So what I want to do is convert that WebSite into an app I can run on a mobile android device or ios. I have read many tutorials on using Apache Cordova, but none of them seem to work with express.
Upvotes: 1
Views: 1549
Reputation: 363
Express, runs a server in the back end. It does not automatically translate to Cordova which is a front end platform. You would need to call your express server from Cordova using AJAX (JQuery, xhr, AngularJS, etc...) and, then, render the website using Cordova.
AJAX Call with JQuery:
$.ajax({
type: "GET",
url: `http://localhost/your/path/goes/here`,
success: function (data) {
// render html and/or data
}, error: function (err) {
// throw error (or do something with it)
}
});
Also, not trying to be harsh, but anything you put on: http://localhost, cannot be accessed by people who are not on your computer (unless you give them your ip address and are running the website), please post any relevant code and/or error messages in the future so others can help you.
Relevant links which expound upon my answer:
How to convert node.js application into cordova
You can refer to here: https://github.com/maximegris/express-cordova-sample for an example (not my GitHub)
If you want to run express from your phone (making your phone a server):
https://www.sitepoint.com/how-to-run-node-js-with-express-on-mobile-devices/
Upvotes: 1