How to use io.js?


#1

Normally here I would include main.js to my index.html file. But this would result in executing script “twice”. Sure, nothing wrong will happen, but I just don’t like the idea. It’s not neat. I’m currently stuck with is:

<!DOCTYPE html>
<html>
  <head>
    <title>Hello World!</title>
        <link rel="stylesheet" href="style.css" />
      <script type="javascript">require('os')</script>
  </head>
  <body>
    <h1>Hello World!</h1>
    We are using io.js <script>document.write(process.version)</script>
    and Electron <script>document.write(process.versions['electron'])</script><br />.
    <script>document.write(os.platform)</script>
  </body>
</html>

Uncaught ReferenceError: os is not defined, so apparently I’m not as good with JavaScript as I thought I was. Could someone help me include io.js libraries (references in global) into a HTML file? In this case index.html, so I could refer to data as easy as at the example lines (also seen above)?

What am I missing?
Sorry for bothering.


#2

Your error is not because node/io is missing but because need to assign the result of require('os') to a variable for later use:

os = require('os')
console.log(os.platform)

#3

Let me facepalm myself real-quick. Thanks.