Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: fs.open

  1. #1
    New Coder
    Join Date
    Mar 2012
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    fs.open

    Noob, Linux, lost...

    I found a bit of sample code I want to mod&use that starts with:
    var fs = require("fs"); then later fs.open, fs.write/read...

    I've scanned the web, searched codingforums and the best I can come up with is NodeJS. I did a download/install and .... no joy.

    Thank you.

    Never mind (for now) it was really late, tired, not thinking (I do that a lot these days) and I CAN"T TPYE.

    I'm back. configure, make, make install -> 'install' finished successfully' - My first time adding external JS modules? I now have a file "fs.js". The code blows out on the first line: var fs = require("fs"); I've tried req(fs.js) with no luck. What do I need to do?

    Thanks
    Last edited by liderbug; 03-09-2012 at 03:12 PM.

  • #2
    Regular Coder
    Join Date
    Apr 2005
    Location
    Texas
    Posts
    448
    Thanks
    24
    Thanked 63 Times in 63 Posts
    There is no require, or include capacity of any kind in javascripts core language. You have to write your own. This has been done by many, and exists in a few libraries already. Google "javascript dynamic script loading"
    Allwisend bin ich nicht, doch viel ist mir bewursst
    -Goethe

  • #3
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,639
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Code:
    var require = function(nm) {
      var s = document.createElement('script');
      s.type='text/javascript';
      s.src=nm;
      document.getElementsByTagName('body')[0].appendChild(s);
    }
    
    require("fs");
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •