Code Monkey home page Code Monkey logo

node-watch's Introduction

node-watch

Simple utility for nodejs to watch file changes.

A file change is:

  • a file whom's mtime is changed
  • a file which is added to a 'watched' folder
  • a file which is deleted form a 'watched' folder

A new feature is to watch folders recurively. However, polling for changes on the file system is slow. And I did not test this module on a large number of files and nested folders.

This utility is handy for e.g. automatic testing in combination with a testing frame-work, An example lives within the JakeFile (jake and docco required)

run: jake autotest

Make changes in the src/watch.js file or the specs/watchSpec.js file and see te specs running automaticly

Install:

 npm install nodewatch

(Use the "-g" global switch for installing nodewatch global)

Usage:

 var watch = require('nodewatch');
 // Adding 2 dirs relative from process.cwd()
 // Nested dirs are not watched
 // dirs can also be added absolute
 watch.add("./spec").add("./lib/watch").onChange(function(file,prev,curr,action){
    console.log(file);
    console.log(prev.mtime.getTime());
    console.log(curr.mtime.getTime());
    console.log(action) // new, change, delete

 });
 
 // Clear (remove) the listeners
 watch.clearListeners();
 
 // Remove dirs to watch
 watch.remove("./spec").remdDir("./lib/watch");

Methods:

 // Add a dir or file relative from process.cwd()
 watch.add("./specs");
 // or
 watch.add("../specs");
 // or
 watch.add("../specs",true);
 // With the last argument = true, the specs folder
 // is recursive watched.

 // Just watch ONE file
 watch.add("../path/to/my/file.js")
 // Add a dir absolute 
 watch.add("/absolute/path");
 
 // Set a listener
 // It will provide a file (filename as string), prev and curr stats objects
 watch.onChange(function(file,prev,curr,action){
        console.log(file);
        console.log(prev.mtime.getTime());
        console.log(curr.mtime.getTime());
        console.log(action); // new, change, delete
  });
 
 // Remove a dir or file (absolute or relative)
 watch.remove("./spec");
 
 // Clear the listener(s) attached via onChange();
 watch.clearListeners();

node-watch's People

Contributors

isakb avatar j-o-r avatar rafeca avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.