Read the statement by Michael Teeuw here.
readFileSync
-
Yeah, I went about it differently than I wanted to. I ended up porting everything to an apache directory so it serves itself as a webapp. Had a few bugs to work out (it was locking up if the json was in the middle of writing when it was retrieved) but I have it working and bug free now best I can tell :)
-
I suppose that’s one way to do that … doesn’t make it very portable or sharable to others. It’s no longer contained within only MM and Node.js … But, if it’s working for you and does what you want, that’s the only thing that matters.
-
Just so you know, the node_helper can serve files as well: https://github.com/MichMich/MagicMirror/tree/master/modules#thisexpressapp
-
I saw that when I was fiddling with some other stuff, but never actually tested it. Is that path relative to the actual module location? Or MM’s installation? Or the user that’s running MM? So if
'/foo/bar/baz'
is defined, where does it start?/foo/bar/baz? (OH PLEASE SAY NO, for the love of all that is sacred, tell me Node.js does NOT allow system reads like that!) $HOME/foo/bar/baz ? $HOME/MagicMirror/foo/bar/baz? $HOME/MagicMirror/modules/foo/bar/baz? $HOME/MagicMirror/modules/<MODULE>/foo/bar/baz?
-
If you are referring to this snippet:
start: function() { this.expressApp.get('/foobar', function (req, res) { res.send('GET request to /foobar'); }); }
The
/foobar
is referring to the url:http://localhost:8080/foobar
-
Ah, so it’s still an HTTP call then, not a simple fileread from disk.
-
Exactly.
-
So then the question is still, where is that
'/foobar'
? What’s that in relation to? The MM install? The module’s folder? -
@KirAsh4 it hasnt got anything to do with a file. It’s just a request, if you want to respond with the contents of a file, you need to do that yourself or use the following method if you want to feed a full folder:
this.expressApp.use("/foobar" + this.name, this.expressApp.static(this.path + "/foobar"));
-
No, it doesn’t have anything to do with the contents. It has to do with where that file resides on the physical system. For example, a request to a default Apache installation will look for a file in
'/var/www/html/'
or'$USER/public_html'
or whatever the system admin has configured it as. In this case, this is a specific request through the Node.js system, being called by MM, so where does it look for that file? Within the user’s folder? Within MM’s installation folder? Within the actual module’s folder? Or does Node.js allow access to the entire file system? So that if I do a call such as:this.expressAp.use("/etc/passwd")
will I actually get the contents of the system’s
'/etc/passwd'
file, or is going to try to read'/path/to/MM-install/etc/passwd'
or some other path?