My question is about:
I am currently trying to connect my electron application to my node server to get data from node.js server and print that data to my electron application. However I don't know how to do it. So could anyone help me:
To get data from node.js server into electron app?
The way you get data from any node.js server is you make a request to that server specifying in the request what you're asking for and the server responds with the appropriate data.
There are literally thousands of ways to physically make the request. The classic way in these days of web technologies is to make an http request from your electron app to an http server in your node.js server. You can make such a request from electron using the request() library.
You would then have an http server as part of your node.js server and you'd specify routes in that http server that handle the requests your electron client is making, fetch the desired data and send the data back as the response. In the node.js world, you can create a simple http server and a few request handlers in a dozen lines of code using the Express library.
This is the general approach. Further details on the exact request to make and URLs to use are dependent upon the details of what you're trying to do and the design you choose, none of which you've shared with us.
Related
As I am a bit beginner
Could anyone help with how can I connect my Front-End (deployed on gh-pages) and backend ( deployed on Heroku) with each other
Frontend consists of simple index.html file and app.js file.
And my Backend consist of server.js file.
How should I make changes to both of them. To integrate with each other.
Some more options have popped up these days but the workflow still used in 99% of apps is:
Client makes HTTP request to server
Server receives request and does something with it
Server responds to the request
Client receives response
Remember that your backend and frontend are 2 separately running programs on different machines.
The 2 most used ways to make your front-end communicate with the backend are:
To communicate you could make an AJAX call (an HTTP request from your javascript)
Complete a form (a form submission send a request to where the Action attribute points)
There are quite a few more possibilities these days but these are the ones you should probably look at first :)
I have a react-app and a python backend. The python API runs on "https://comapny-api.com". I define the URL in my .env file. Now I would like to implement a Node.js server in the middle. I just want that nodejs server to get the request from the client and send it to the python side and return back the response sent by the backend to the client. The only reason I am doing this is that I do not want anyone to know the final API endpoint I hit. In the network tab, I show the nodejs server URL so the end user is unaware of the final API endpoint. Is my approach a good one to take? If yes, can I write just a single method using express to handle this? Please advice.
app.get('/', function (req, res) {
res.send('root')
})
Will this template work? For example, if I call https://nodejsserver.com/years, will it hit this '/' GET endpoint and in turn call in my final API /years endpoint. I am wondering how can I call a generic endpoint in express, one for get and one for post and get the URL from req.params and call the python API with req.params. Thanks
If you have clear react-app without server logic, you can build react-app as js bundle and use it as static, and your python backend becomes the only web-server.
This approach advantage is infrastructure simplification (minus one backend and you still can debug your front separately), but some server logic can become more expensive, like ssr and routing.
I am building my first full stack application. I have two seperate apps, a client app built with create-react-app and a node express server to serve json.
Currently, my create-react-app which uses Redux, makes ajax calls using axios to the port that my server is running on. I have set up authentication for the server to exchange a token with my client upon success.
My goal is to make use of the Spotify API. For their authentication, it says I need to get a authentication token from their server via my server.
I am not sure the proper way to go about this.
Currently my thought process is to have my client hit a new route in my server via a axios ajax call to have my server asynchronously exchange the token with the spotify api and then send it back to the client.. is this the proper way?
I've seen various other examples of this being done but they have their node/express app manage the routes for their entire application.
Any help would be greatly appreciated thanks.
I'm new to node.js and my question is quite a dumb one. I have created my restful api that does something but the problem is i have to call server.js file in the cmd. I want to create file called client.js that request the service from server.js and server.js will perform the job and return the result to client.js which will be shown to user.
You need to communicate via JSON data. When client accesses some url in server application, server application should provide data in JSON format.
Example - Server provides a list of people who have registered to your site. Than code your server in such a way that when client accesses www.example.com/accounts/users (where www.example.com is where your server is running), server should return a JSON response which client can than use to display.
I just started learning AngularJS for my website development, and its perfect for what I need. However, I'm very new to web programming and I've been looking for the answer to my question for a while now, and I couldn't get a clear response. I'm wondering how I can handle incoming HTTP Requests in my AngularJS application.
For example, I'm going to have a computer running a program that is going to be constantly sending HTTP Post requests with data to the web server running my Angular app. I want to be able to parse the information in the app, and display the data using Angular's data binding. But, I can't figure out how in Angular you can listen for incoming HTTP requests, parse the data, and send back a response.
AngularJS is designed for front-end web apps. You use to make an HTTP request from the users web browser to a webserver listening for such calls. But angular itself can't listen for them.
If you want to be able to listen for a HTTP request you will want to try either apache/php or nodejs/express. nodejs will probably work best for you because you can program in javascript.