node package manager
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »



This controls flow by events like flags.


If you want to make a http server serving a static file and load file before handling the requests, you can put http.createServer() in the callback of fs.readFile(). But it makes a too deep nest. Now, with EventSync, you can write the code like this.

var fs = require('fs'),
    http = require('http'),
    EventSync = require('evsync');
var evsync = new EventSync();
fs.readFile('foo.txt', 'utf8', function (err, data) {
  if (err) {'error', err);
  } else {'load', file);
http.createServer(function (req, res) {
  evsync.once('load', function (file) {
  evsync.once('error', function (err) {
    res.end('Failed to load the file.');