For the server-side portion, you just need to use a static-files module. As to file encoding, I would recommend having all your text files in UTF-8 without a Byte Order Marker (BOM), many utils blow up without them, and many editors in windows by default inject them for new files, so that's something to be aware of. SERVER: See connect.static() for an example.http://www.senchalabs.org/connect/static.html CLIENT: As to loading your files, jQuery's .get() method, which should give you what you are wanting...http://api.jquery.com/jQuery.get/
> Subject: Re: [nodejs] Module for loading JSON or other text file in browser > or node > From: [email protected] > Date: Tue, 30 Jul 2013 16:25:28 -0500 > To: [email protected] > > On Jul 28, 2013, at 22:41, Ryan Schmidt wrote: > > > I want them to be dynamically loaded, from their original locations, as > > needed. > > I guess what I want is: > > loadFile(file, function(err, contents) { > if (err) { > console.log(err); > } else { > //do something with contents > } > }); > > where the browser implementation of loadFile (which I've written) deals with > all the XMLHttpRequest mechanics, and the server implementation could wrap > fs.readFile. So far I'm unsure how to deal with character encoding. > > I wanted to avoid the problem that I've seen many times on this group > already, namely I didn't want to write and publish and announce such a module > only to have people refer to me to the existing module that did exactly what > I wanted. > > I'm just surprised nobody has published such a module yet. Nobody else needs > to load text files into their server- and client-side JavaScript libraries? -- -- Job Board: http://jobs.nodejs.org/ Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines You received this message because you are subscribed to the Google Groups "nodejs" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nodejs?hl=en?hl=en --- You received this message because you are subscribed to the Google Groups "nodejs" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
