Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

File System I/O in Javascript using V8

I was under the impression that these days javascript can be used as a proper general purpose programming language outside of the browser using standalone interpreters like V8 or SpiderMonkey. So I went ahead and installed V8.

However, the first thing I wanted to do was read in a file and do some processing. I looked around and didn't find an obvious way of doing this using JS/V8.

My intuition tells me that there has to be a wrapper function around the C++ file i/o functions in V8. Has this already been done or is this something that I need to implement myself? Or perhaps I'm missing the whole point!?

Thanks for any help you can provide!

like image 712
Tim Merrifield Avatar asked Dec 17 '10 03:12

Tim Merrifield


1 Answers

There's a project called nodeJS designed for this: http://nodejs.org/ - and it's just starting to become really popular.

Examples specific to file IO are here: http://nodejs.org/docs/v0.2.5/api.html#file-system-104

If you're going to use nodeJS, the website only shows the core functionality, so don't forget to check out the existing libraries (called modules) built for node: https://github.com/ry/node/wiki/modules

The focus at the moment is on nodeJS-based web servers and network-based applications but the modules link includes many other things, including parsers, daemons, and bindings to linux's notification system (just to give you a taste of the diversity there).

like image 195
David Tang Avatar answered Sep 28 '22 17:09

David Tang