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

wigwam

v0.1.2

Published

A module for creating restful API servers and static file servers (with etags, caching, etc).

Downloads

21

Readme

Wigwam

A module for creating restful API servers and static file servers (with etags, caching, etc).

Web server is like a house, some are small and tiny, some are big and fancy. And if you're goin gto live there alone or with small family of two-three people, you don't huge mansion with 10 rooms and 15 bathrooms, it will take all your time to maintain teh thing with no clear advantage. Same with the webservers, it's easy to install all-included frameworks like express, but do you really need all of it's features all the time?

Install

$ npm install wigwam

Examples

Assume:

var http      = require('http')
  , path      = require('path')

  , Wigwam    = require('wigwam')

  , publicDir = './public'

  , wigwam
  ;

1. Simplest, static files only, no api, no websockets

wigwam = new Wigwam(http.createServer(), {path: publicDir}).listen(11337);
console.log('Listening on 11337');

2. All in one

Wigwam(http.createServer(),
{
  // static files
  static:
  {
    path: publicDir,
    url : '/'
  },
  // api endpoints
  api:
  {
    path: '/api/v0',
    get:
    {
      'test/:test': function(params, callback)
      {
        // successful response
        callback(null, {method: 'get'});
      }
    },
    post:
    {
      'test': function(params, callback)
      {
        // successful response
        callback(null, {method: 'post'});
      },
    }
  },
  // websocket events
  websockets:
  {
    transformer: 'websockets',
    events:
    {
      'connection': function(socket)
      {
        console.log('connected');
      },
      'data': function(socket, data)
      {
        socket.write({echo: data});
      },
      'error': function(err)
      {
        console.error('Something horrible has happened', err, err.message);
      }
    }
  }
}).listen(11338);
console.log('Listening on 11338');

3. Step-by-step, Static + API + Websockets

// Create server instance
wigwam = new Wigwam(http.createServer());

// Static files
wigwam.static(
{
  path: publicDir
});

// API endpoints
wigwam.api(
{
  path: '/api/v1',
  get:
  {
    'test/:test': function(params, callback)
    {
      // unsuccessful response
      callback({code: 500, error: 'for get'});
    }
  },
  post:
  {
    'test': function(params, callback)
    {
      // parse POST parameters
      this.parseRequestBody(function(err, data)
      {
        // unsuccessful response
        callback({code: 500, error: 'for post'});
      });
    }
  }
});

// Websocket events
wigwam.websockets(
{
  transformer: 'websockets',
  events:
  {
    'connection': function(socket)
    {
      console.log('connected to :11339');
    },
    'data': function(socket, data)
    {
      socket.write({echo: data, port: 11339});
    }
  }
});

// Start listening
wigwam.listen(11339);
console.log('Listening on 11339');

4. Verbose handlers

// Start with server + settings
wigwam = new Wigwam(http.createServer(),
{
  path: publicDir,
  apiPath: '/api',
  transformer: 'websockets'
}).listen(11340);
console.log('Listening on 11340');

// GET endpoint
wigwam.get('test/:test', function(params, callback)
{
  // successful response
  callback(null, {parameter: params.test, method: 'get', port: 11340});
});

// POST endpoint
wigwam.post('test', function(params, callback)
{
  // parse POST parameters
  this.parseRequestBody(function(err, data)
  {
    // successful response
    callback(null, {data: data, method: 'post', port: 11340});
  });
});

// combined events handler
wigwam.on('connection data', function(socket, data)
{
  if (data.connection)
  {
    console.log('connected to :11340');
  }

  socket.write({echo: data, port: 11340});
});

// Single event handler
wigwam.on('disconnection', function(socket)
{
  console.log('bye, bye');
});

TODO

  • Tests
  • Better docs