0

I have a web application with a client that receives data from a server. I have the data in NodeJS, but I want to pass the data to a Javascript file. The Javascript file is included in a HTML file, so I can't make the files communicate with eachother.

I am new to NodeJS, so it can be a stupid question, but anyones help is appreciated

This is for a project where I need have a data stream, and I need to pass it into a web application. I tried to pass the data to different page inside my application and then I tried to get that data on that page inside my web application via Javascript, but I couldn't make that work. I'm not even sure if its possible at this point.

6
  • 1
    If you have a web application then you have some backend, why not make a get request to it from the javascript (by returning JSON)? Commented Jun 27, 2019 at 7:15
  • 1
    You can use the XMLHttpRequest for doing that, and if you have implemented jQuery on your front, you can use ajax. Your node server can't communicate with your front-end but your front-end can call your node server, so with a get request as said @tomerpacific before you can get your data. For that you have to open a route with your express app. Take a look on : developer.mozilla.org/fr/docs/Web/API/XMLHttpRequest and expressjs.com/fr/guide/routing.html Commented Jun 27, 2019 at 7:23
  • @BenoitChassignol Thanks I'll take a look! Commented Jun 27, 2019 at 7:26
  • 1
    Your front-end can in-fact communicate with the front-end, via a websocket! Commented Jun 27, 2019 at 7:27
  • @mHvNG Tell if it's all right for you i gonna put my comment as an answer. Commented Jun 27, 2019 at 7:28

1 Answer 1

1

Your node server can't communicate with your front-end without a specific way of communication like websocket, you have many other way to communicate with your front-end as node-server, take a look at server send event for example.

By the way your front-end can call your node server more easely with a get request as said @tomerpacific in comment.

For that you have to open a route with your express app. Routing with express And for call it on a GET request, for that you can use the XMLHttpRequest, and if you have implemented jQuery on your front, you can use Ajax jQuery.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.