Push new data from Node REST API to React-Native - javascript

Problem
I've created a REST API using Node and a client app using React-Native.
So far I've configured it so the client app makes HTTP requests to the server.
Now I need to push new data from the server to the client as soon as it is available. I need to push different data to the client app depending on which user is logged in.
I haven't done this before and I've been having trouble finding a good solution online, partially because I don't know the correct terminology.
The server will pull the data from an external API, save it to MongoDB via Mongoose. I then need to push the new data to the client
If anyone has any suggestions that would be great!
Environment
Node.js with Express v4.16.4
React-Native v0.58.0-rc.2
Mongoose v5.4.5
Firebase is already installed in the react-native app. I'm proficient with both Mongoose and Firebase so either one could be good for the push queue if applicable.
Thanks!

1. can use socket.io
Server send data to client using Web socket(socket.io).
2. can use firebase push notification.
Server can create new notification to firebase, and client can received signal from firebase, and get data from server via REST api.

Related

Getting data from ERP in mobile APP how to do it properly?

I’m building an app and I need to communicate with the ERP that uses webservices and is most of the time reliable.
My backend is a Graphql api I’m wondering how should I get the data from ERP?
The options I’m considering:
Fetch the data from ERP on every request from the app and save it to my separate DB.
Create a cron job and copy the data every X time to separate DB.
Create a microservices server and update the data in the queue on every request.
Or is there another solution I’m not seeing?
The problem is that the ERP web services are not as reliable as my separate DB.
Right now I have the 3 packages the backend the server that gets the data from EPR and react native client.

How to pull new data from API using node / electron desktop application?

I'm creating a private desktop application for my Shopify store and was wondering what the best way to continuously pull new order data down from their API? While the application is open do I query the API for new orders at a set interval? Is there a way to use webhooks with a desktop application (not a server)? Any suggestions would be appreciated!
You definitely need a server to receive webhooks, but if you don't want to manage a server, you can use a serverless solution such as Amazon EventBridge.
For example, you can do something like the following:
EventBridge receives your order data through the Shopify webhook.
The order data is added to an SQS queue.
Your desktop app connects to the SQS queue to receive the order data.
Here is a tutorial from Shopify that explains this approach:
https://shopify.dev/tutorials/manage-webhook-events-with-eventbridge

Which method is better: Python SDK (server side) or JavaScript SDK (client-side) to add to and update cloud firestore?

I have a Django web application with a postgresql database on an AWS server.
I want to keep this database in sync with a nosql cloud firestore database. We're using cloud firestore as the backend for a mobile app.
This means that every form update or new object that is added to the web app needs to be in sync with cloud firestore.
I'm able to update cloud firestore using the Python SDK when each form is submitted via the web app. However, I want to know if this is the best method to keep these two databases in sync. Each time a form is submitted, I have to import the firebase SDK, and then use the methods to update cloud firestore. Obviously, this will take time, but I'm unsure if this method is better, or if using the JavaScript SDK will be better. In essence, which method will perform better?
When you are doing that from python SDK the read and write to cloud fire storage is done from the server means if you have x request and y number of users doing that, your server has to do x*y request to Cloudflare storage. in this case, your transaction from the server will be heavily based on a user basis but you can use admin SDK in python and give only admin to access to DB.
If you want to use js for the same then request will be shared by users and the server will be free but each user should have access to DB write and read, you have to be more careful about authenticating users.
so if its all read requests and user-based filters are done well use from js, if you have doubts on authentications or you don't want to take a risk in that use from python.

Passport.js - use same token for different server

I'm using passport.js and MongoDB for user login and postAPI authentications. However whenever I deploy my node server to another AWS instance, I need to go through the signup process, do the login and get a new token.
I know I can see the saved users and their jwt tokens from MongoDB. Are there anyway that I can copy the token and, when initialize new database, save the same username-jwttoken pair by default, so I can use the same token string (not with password, though it is more easily to be done) to pass the passport authentication test?
Thanks!
It sounds like your deployment process involves tearing everything (application and MongoDB) down & rebuilding from zero, possibly with some seed data but without any of the "live" data in the AWS instance. Here are a couple of ideas:
copy all the data from the old MongoDB instance to the new one as part of your deployment process. This will ensure that the users are present on the new instance and (should) ensure that users don't have to go through the signup process again. I'm not too familiar with MongoDB so I don't know how to do this, but I'm sure there's a way - maybe you can copy the data files from one to the other?
set up your environment with two servers: a MongoDB server and an application server. This way you can tear down your application and create a new AWS instance just for the application without touching your MongoDB server. Just update the MongoDB connection configuration in your new application instance to point to the same MongoDB server you've been using.
The first option is more suitable if you have a very small application without too much data. If your database gets too large, you're going to experience long periods of downtime during deployment as you take the application down, copy the data out of the old Mongo instance, copy the data into the new Mongo instance, and bring the application back up.
The second option is probably the better one, although it does require some knowledge of networking and securing MongoDB so that only your application has access to your data.

Node.js client api key

I have a node.js backend for an ios app that will provide json data to the app. I want to handle client authentication for each app. The users do not need to create an account. I only want to identify the client apps when providing data and save some data for each client on the node server.
How do I handle identifying each app on the server?
If I need to create an API key, how do I handle that?
If there is a way to authenticate the app when the app first accesses the API, how can I create a unique identifier for the app?
Last, what do I need to know before I deploy the node server? Can I get away by just pointing a domain to my router, opening a port and serving the api from there or is it a must to have a web server setup to handle that?
Thank you
You can basically find a lot of blogs posts to get best practices to follow when designing an api. But here is an over all idea
You can create a client key and send it on every api request or add as part of url
Example: api.example.com/v1/users?client=android&version=1.1
Use Middileware. You can either name as to your convenience or have a database to store key value to manage your clients.
Example:
Create a Middleware which does the handling of authentication and API key checker before you forward it to the routes.
android => 0, ios => 1, web => 2
url: api.example.com/v1/users?client=0&version=1.1
There are many ways to create api keys. Here are some of them
UUID - https://www.npmjs.com/package/uuid
Json web token - https://github.com/auth0/node-jsonwebtoken
Oauth - https://github.com/ciaranj/node-oauth
Again, You have a lot of online posts explaining best practices to follow in production. If express.js, You can find best practices to follow here Express Production
This is just an overview. I request you to do a lot of research online and ask a relative more concrete problems you face towards your learning.

Categories

Resources