I suspect your last line is the actual question?

On Sunday, September 18, 2016 at 1:28:38 AM UTC+2, ABC DEF wrote:
>
>
> Would the best way to be to set a variable in HTML to "input" and get Node 
> to write the data to it when it is received, and somehow get JavaScript to 
> read that variable and set it blank when it is done with it? Some intuition 
> would be appreciated. Thanks.
>

That actually depends on what you want to do.

One way to do this is, fetch data from a "distant Java server" with Node 
and prepare a HTML page that your clients (browsers) will consume. Example, 
to set an input value, you would create:

- a *fetch-data.js* service, to fetch data from the distant Java server:

import request from 'request';
const distantJavaServerUrl = 
'https://distant-java-server.com/api/endpoint-for-your-data-in-invalid-format'
;

export function fetchData() {
  return new Promise(resolve, reject) {
    request('http://www.google.com', function (error, response, body) {
      if (!error && response.statusCode == 200) {
        // Assuming this is JSON data:
        resolve(JSON.parse(body)); // or format it better
      }
      reject(new Error('Upstream error.'));
    });
  });
}


- a *views/my-file.ejs* html template (omitting a lot of boilerplate):

<html>
<body>
    <input value="{{ someCount }}">
</body>
</html>

- a node.js server and handler for requests for this file:

import express from 'express';
import { fetchData } from './fetch-service';
const app = express();
app.set('view engine', 'ejs');

app.use(function(req, res) {
   fetchData()
  .then(data => res.render('my-file', data))
  .catch(err => res.status(500).send('Server error.\n'));
});


app.listen(8080, () => console.log('Listening on 8080')); 

You can then get your HTML with data here:
[zlatko@zlatko-desktop ~/tmp]$ curl localhost:8080
<html>

<body>
    <input value="12345678">
</body>
</html>
[zlatko@zlatko-desktop ~/tmp]$


Now, by playing more with your fetch-service.js, you could transform the 
data in the way you like it. Playing more with the .ejs file, you can 
format the input, you can name it, add buttons and styles and javascript 
and other things that make a web page a web page.

Now, how to "read and clear a file/variable which Node also can" is a valid 
question, too, but it's more of a frontend question better answered on some 
frontend group.

Now, this is all very basic because you're not asking a specific question. 
So although JavaScript and Node.js are not very limited in what they can 
do, it might be challenging if you don't know what you want to achieve. So 
I would recommend studying a Node.js application design, maybe by following 
a good book, a video tutorial or other resource would help overcome that 
challenge.


-- 
Job board: http://jobs.nodejs.org/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to nodejs+unsubscr...@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/e1fefdf6-b7a0-42e7-9d37-7241c8324bb8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to