Node.js Example File Read and Write

Reading and writing files in node.js is as simple as this example:

var fs = require('fs')
  , sys = require('sys');

fs.readFile('treasure-chamber-report.txt', function(report) {
            sys.puts("oh, look at all my money: "+report);
});

fs.writeFile('letter-to-princess.txt', '...', function() {
             sys.puts("can't wait to hear back from her!");
});

The snippet is taken from “understanding node.js“. Also take a look at how-to-node for other essential stuffs when starting programming node.js.

About these ads

About minghuasweblog

a long time coder
This entry was posted in All, node.js and tagged , , , , , . Bookmark the permalink.

One Response to Node.js Example File Read and Write

  1. JaneS says:

    Normally I don’t read article on blogs, however I would like to say that this write-up very forced me to take a look at and do it! Your writing taste has been surprised me. Thank you, very nice post.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s