javascript - Communication between an express node server and its displaying html -
really fast, question may have been asked, not totally clear on terminology , have had no success when searching solution.
i attempting create simple web application can receive , post requests. then, take information receive these requests , use them in javascript file embedded in html displayed. think may more clear code. app.js:
var express = require('express'); var app = express(); var assert = require('assert'); app.use(express.static('javascript')); app.get('/', function(req, res) { res.render('index.jade'); }); app.listen(3000);
i able take information received or post request, in json format, , able use in javascript have linked index.jade. make matters more confusing in index.jade line is:
include map.html
so ideally able information javascript in html file.
i want able pretty continuously update map.html using javascript based on frequent , post commands.
this simple solution, pretty new web application programming in general, , have been struggling problem. in advance, , ask if need clarification.
the way want able call endpoint (lets assume /awesome) pass info , write javascript file can reference in html.
something below write main.js file in public folder. can make write whatever want.
var fs = require('fs'); fs.writefile("/public/main.js", "console.log('hello!')", function(err) { if(err) { return console.log(err); } console.log("the file saved!"); });
you can reference /public/main.js in html.
check that: writing files in node.js
if misunderstood intentions, apologies. :)
Comments
Post a Comment