node.js server for ionic application - node.js

I am developing a mobile application using ionic framework. I want to use node.js for developing the server to make REST api calls.
Where should the node.js code be included in the project?
How to deploy such an app as apk? and how to test it?

Ionic is based on cordova and it is used to create mobile applications in javascript.
Node.js is based on V8 and it is used to create backend (server) applications in javascript.
Node.js code cannot run on mobiles.
So you have two seperate projects.One is the frontend ionic mobile app. And the second is the backend nodejs app.
To make a connection between the two, as ionic uses angularjs take a look at angular's http service. After that you can organize your code in services. For example:
http_calls_service.js or api_service.js
As for the testing there are several frameworks to work with. Take a look at this.

Related

Can you easily explain the process of deploying ionic (based on react) apps with a node backend?

I recently started using react with a node server as a backend. I'm having problems to understand how to deploy such an app. I'm a beginner with ionic and deploying websites (or rather web based mobile apps) so I apologize if this is an easy/stupid question.
I searched a lot about this but my brain is still struggling to understand the deployment process. As I understand, any website have generally two parts, the frontend built with HTML/CSS/JS and the backend built with nodejs (in my case). If I want to run the app, I need to type npm start in the terminal right? so I'm only running the node server actually, where it will serve the HTML pages (static pages) depending on which url endpoint I wrote, right?
So deploying this is "easy" by copying the static files into a remote server and just run the nodeJs server to serve pages depending on the request, right. Therefore, is the start command here npm start, which will start the whole app.
I'm now using the ionic framework with react syntax and nodejs in the backend. There is a special command to run the ionic app (frontend), which is ionic serve. So if I run this the frontend will show up in the browser. Furthermore, I need to run the node server with npm start to handle requests. Therefore, to start my app, I need the ionic serve and npm start commands. How can this be deployed?
After some research, I read that I need to deploy the ionic app (frontend) and the backend separately. For example the ionic app would be a webapp and the server also a separate webapp (since I'm using MS Azure). The communication between them can be over rest API or web sockets as I understand. Is this the right approach to do this or there is a better/more clear way?
deploying two apps would mean that I need to pay for two apps on azure. Is there a way to minimize costs and have a functional app?
PS: generally, I'm having problems to understand the deployment process. I understand basically how the web works and I can build website on my machine but I'm not confident about my skills when it comes to deployment. Surprisingly, there is not much on the internet about it. Can someone please recommend articles, books or ideally videos that explain this process. Thank you in advance.
here is how you deploy ionic apps as pwa - https://ionicframework.com/docs/react/pwa
if you are using a node backend, the you would start the server same as you would normally, If I am understanding the question
Though your question is not specific to a particular issue but highlights a wide variety of issues, i will still try to explain it.
Ionic is primarily used for creating HYBRID/WEB MOBILE APPLICATIONS. Although you can deploy the code as a website too, but you will not be able to get any benefit out of using ionic for a website only and not using react as a standalone framework.
Be clear on your requirement, your question talks about website and web based mobile apps. Deploying a website and a hybrid mobile application is not one and the same thing. Websites are hosted on servers, mobile apps are deployed in app stores.
If you are not going to deploy to any mobile platform, i suggest you drop ionic and build your website with react.
Now coming to Ionic mobile apps, this is the flow
Create Ionic Project -> Build project for iOS/Android platform -> Deploy these apps to respective app stores
You will not host your Ionic mobile code on any hosting provider.
Your node.js backend code gets hosted on a hosting service. The endpoint URL will change to your hosted servers IP address.
Read about following topics first
What are hybrid mobile applications
What is Ionic
How to build mobile apps using Ionic
Publishing Mobile Applications
Deploying node.js to a cloud host

how to deploy an ionic-react app to mobile if I'm using node js server in the backend?

I discovered ionic this week and I'm really considering using it at work.
Basically, my goal is to build an app that will work on android and Ios, where the needed functionality is to connect to the cloud over web socket and pull data from the cloud and show it on my phone. Maybe later I'll eventually need to consider using login but not for now at least.
Normally, if I'm building a web app. I ll use nodejs to pull the data from the cloud and expose it to the frontend. I ll write all code together and I ll host my app in Heroku or something where the entry point is my nodejs server right? So that my server needs to start and it will take care of the rest.
This is a bit confusing in ionic since I need to start the app with ionic serve, but somehow I also need to start my nodejs server too right? So I assume I can't write the server-side code inside the ionic app or am I wrong?
There is not much about this on the internet but I did some research and I guess that I should deploy (host) my nodejs server in the cloud (maybe using Heroku) and then connect to the server from my mobile app over the socket. Is this the right/only way to do this? are there any security issues with this method?
I find ionic great but I'm not sure if I should use it at work. Sincerely, this use case of using a backend server with ionic made me confused.
Ionic looks ideal for building cross-platform apps that does not need server-side scripting, but how complex can it be if I want to integrate some server-side code in my app? especially as I said I'm going to use some login forms in the future to extend the functionality of my app.
PS: I'm using ionic 6.10.1 and specifically I'm interested in using ionic with react not with angular.
After some search, I discovered that it isn't possible to deploy the frontend and backend code together. Therefore the trick is to deploy the nodejs server separate from the frontend.
Precisely, if it is a web app, then you should deploy the nodejs server in a separate host from the frontend. Then by starting the frontend app, you can communicate with the running nodejs server via socket or REST API.
Hope this helps someone in the future :)

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:
Install node.js / express / socket.io in your linux server.
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.
In Cordova App, use something like socket.emit('FromClientToServerCallAPI', data) to call an api.
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)
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.)

Integrate Node.js with Angular 2 application

I am creating an angular 2 project which will use Node.Js as backEnd and Node.Js will make calls to 3rd party external APIS(Like Gandi) which accept calls only from Python, PHP or Node.Js.
I have chosen Node.Js.
I have called few APIs from Angular 2 services using HTTP protocol. Now I do not know where to write this Node.Js code and how to Integrate this Node.Js code with Angular 2 services.
I think, Just a sample application or sample architecture which is a combination of Node.Js and Angular 2 will help a lot.
Do I need to create Restful services using Node.Js?
If Yes, Do I need to use Express.Js also for server purpose?
Note: I do not want a Mean Stack application(No Mongo DB)
Actually it's pretty straightforward.
What I'd do is to simply consider the Angular 2 app on the frontend and the Node.Js API on the backend as independent projects. It's very likely that they will run on different providers (eg. Firebase for Angular 2 app and Heroku for the Node.js server) so it makes sense to handle them as 2 different projects with it's unique dependencies.
I have recently done a similar project, using Angular 2 + webpack as frontend and Django on the backend: https://github.com/damnko/angular2-django-movies
Hope this makes sense, otherwise please let me know
i think this repo will serve your purpose.
https://github.com/singh15/feed-server
which is using twitter api to get data and send that data to any front-end.

Do I need Node.js or Express to deploy my Angular 2 app?

I am working on a food purchase web app. The app has already been launched on mobile (Android). Now we want to build a web version.
The backend of this app was built using Node, Angular and Firebase.
I would like to know if I can only use Angular 2 (without Node.js) for the web application. What the web app will basically do is to:
User authentication
Consume Backend API
Checkout, after purchase
My major concern is, do I need Node.js for anything? Or is Angular 2 just enough for my frontend development and deployment?
Angular is your front end.
Nodejs is your backend.
Firebase is a cloud backend that I assume you're handling your user Authentication in....it's easier than DIY if you aren't backend savvy.
Depending on what Node is doing, then you might be able to remove node and rely entirely on Firebase(big maybe...).....I suggest not touching anything becuase you clearly aren't a backend engineer. Node is probably hosting your app's API and/or connecting to your database.
Yes, you can switch to a different backend from node like PHP or .Net and it will work with Angular2. You will need some sort of backend(Angular2 is 100% front End).

Resources