npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

express-easy-livereload

v1.4.2

Published

Express middleware to use livereload2 easily (both server and client)

Downloads

8

Readme

easy-livereload

Build Status npm version

This is yet another library to use livereload very easily for express/node.js-based development. It is express middleware which provides both a livereload server and a javascript client. It is designed to be used with node-dev so that restarting a server process is also possible.

The major features of this library include:

  • using livereload (PROTOCOL 7) server code from the original author,
  • using livereload.js client code from the original author,
  • using fs.watch() to check file changes instantly,
  • allowing to automatically restart server code (if invoked with node-dev), and
  • all-in-one package to enable with at least one-line code.

Install

npm install easy-livereload node-dev

Usage

Minimal configuration:

app.use(require('easy-livereload')());

Typical configuration:

var path = require('path');
var express = require('express');
var app = express();

if (app.get('env') === 'development') {
  var livereload = require('easy-livereload');
  var file_type_map = {
    jade: 'html', // `index.jade` maps to `index.html`
    styl: 'css', // `styles/site.styl` maps to `styles/site.css`
    scss: 'css', // `styles/site.scss` maps to `styles/site.css`
    sass: 'css', // `styles/site.scss` maps to `styles/site.css`
    less: 'css' // `styles/site.scss` maps to `styles/site.css`
    // add the file type being edited and what you want it to be mapped to.
  };
  
  // store the generated regex of the object keys
  var file_type_regex = new RegExp('\\.(' + Object.keys(file_type_map).join('|') + ')$');
  
  app.use(livereload({
    watchDirs: [
      path.join(__dirname, 'public'),
      path.join(__dirname, 'app')
    ],
    checkFunc: function(file) {
      return file_type_regex.test(file);
    },
    renameFunc: function(file) {
      // remap extention of the file path to one of the extentions in `file_type_map`
      return file.replace(file_type_regex, function(extention) {
        return '.' + file_type_map[extention.slice(1)];
      });
    },
    port: process.env.LIVERELOAD_PORT || 35729
  }));
}

By default this script tries to load the live reload script itself, but if that doesn't work for some reason then you can put your app into the easy-livereload options. This will add a local variable to your app under app.locals.LRScript.

var express = require('express');
var app = express();
var livereload = require('easy-livereload');

if (app.get('env') === 'development') {
  app.use(livereload({
    app: app
  }));
}
doctype html
html(lang="en")
  head
    title Livereload
    
    != LRScript //- loads the livereload script

Example scripts entry in package.json:

"scripts": {
  "start": "NODE_ENV=production node app.js",
  "start-dev": "NODE_ENV=development node-dev app.js"
}