Huh, I didn't even know you could write server-side javascript. I guess it could have significant advantages. I pretty regularly write php code to generate javascript. And a few times in my career, I've written php code to generate javascript to generate HTML. Actually, that is exactly what I am up to. I am kind of into Dungeons & Dragons. I scanned in the 5th edition players handbook so I have the tabular data in a text file. I wanted to convert that to yaml and then write javascript to do the calculations the game requires. It looks like I'll have to stick with writing php to generate javascript. For example, if you are playing a character with strength 18, he gets a +4 bonus when doing something related to strength. Its called an ability score modifier. So to determine if he succeeds at whatever he is trying to do, you roll a 20 sided die and add 4. Right now I have the php script put a link on the page to call a javascript function that generates a random number between 1 and 20 and adds 4. But that's not portable. I was hoping to do the whole thing client-side so I could email the thing to my friends. On 8/6/19 4:17 PM, Ben Mustill-Rose wrote:
Hi
What you've done here is installed a package for a serverside language (in this instance Node) and are now trying to use it in the browser which won't work. As it so happens it looks like JS-YAML has instructions for using a browser also.
There are a couple of different ways you could go about this:
If you don't want the YAML to be directly accessible by the public you're going to have to write some kind of web app, potentially using Node with a framework like Express that has access to the file system. You'd then use JS-YAML to parse the YAML and construct the HTML serverside which would then be served to visitors when they hit the apps URL.
If you don't mind the Yaml being directly accessible you could do it all on the client using the (all be it very breef) instructions on the "Bundled YAML library for browsers" section of this https://github.com/nodeca/js-yaml page.
Cheers, Ben.
On 8/6/19, John G Heim <jheim@math.wisc.edu> wrote:
Can you load a javascript module in a script embedded in a web page? If so how?
I am trying to write a web page to display values in a yaml data file. I want to read this yaml data, parse it, and display the values. I found there is a javascript module available to do that. I installed it on my linux machine with the command 'apt-get install node-js-yaml'. The examples that come with the code don't work when embedded in a script on a web page. The line where it fails looks like this:
var yaml = require('js-yaml');
I have been googling all day but all I can find are more examples that do not appear to be embedded in a web page.
-- John G. Heim; jheim@math.wisc.edu; 608-263-4189 _______________________________________________ Blind-sysadmins mailing list -- blind-sysadmins@lists.hodgsonfamily.org To unsubscribe send an email to blind-sysadmins-leave@lists.hodgsonfamily.org