Showing posts with label cloud 9. Show all posts
Showing posts with label cloud 9. Show all posts

Friday, April 6, 2012

Timers in Node.js


You can use the JavaScript timers, such as setTimeout(), clearTimeout(), setInterval(), clearInterval() in your node apps. All of the timer functions are globals. You do not need to require() this module in order to use them.
To schedule the repeated execution of callback every delay milliseconds you can use the setInterval() method. The setInterval returns an intervalId which can be later used to clear the interval execution with the clearInterval() method.
Similary to schedule execution of a one-time callback after delay milliseconds use the setTimeout() method. Read more...

Thursday, April 5, 2012

File I/O in Node


The fs module provides both synchronous and asynchronous ways of reading files. The readFile method reads the contents of the file asynchronously.
fs = require('fs');
fs.readFile(file, [encoding], [callback]);

where file is the name of the file to read, encoding is an optional parameter that specifies the type of encoding to read the file. Possible encodings are 'ascii', 'utf8', and 'base64'. If no encoding is provided, the default is utf8.callback is a function to call when the file has been read and the contents are ready - it is passed two arguments, error and data. If there is no error, error will be null and data will contain the file contents; otherwise err contains the error message.
Similarly the writeFile method writes content to a file specified in the function. Read more

Sunday, April 1, 2012

Creating a Node.js program in Cloud9 IDE

Cloud9 IDE is an online development environment for Javascript and Node.js applications as well as HTML, CSS, PHP, Java, Ruby and 23 other languages. Cloud9 IDE lets you build, debug, and run your Node.js applications within the browser. Set breakpoints, follow the call stack, and analyze your performance. In this post I’ll demonstrate how to build a simple Node.js server app using Cloud9 IDE. Read mode...