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

censeo

v0.6.0

Published

Run arbitrary JavaScript or PogoScript on a server

Downloads

36

Readme

censeo

Run arbitrary JavaScript or PogoScript on a server.

Please use this responsibly.

Preferable only in test code

Insructions

First of all you need to start up the server specifying a port number to use. If you are using karma you may want to put this in your karma.conf.js file.

require('censeo').server.listen(3001)

or if you already have an http server

require('censeo').server(http)

Next you want to create a client:

client  = require('censeo').client(3001)

where 3001 is the port censeo is running on

Then in your test (you should only use this for tests!).

client
  .run(function() {
    return 1 + 1;
  }).then(function(result){
    expect(result).to.equal(2)
  })

or

client
  .run(function() {
      var fs = require("fs");
      return new Promise(function(success){
        fs.readdir(process.cwd(), success);
      });
  }).then(function(result) {
      expect(result).to.include("node_modules");
  });

Where censeo can come in really handy is if you need to spool up a webserver to test against. To do this we use runTask which lets you start a task and stop it at a later point:

client
  .runTask(function() {
    var http, app, server;
    http = require("http");
    app = http.createServer(function(req, res) {
        var headers;
        headers = {
            "Content-Type": "text/plain",
            Connection: "Close",
            "Access-Control-Allow-Headers": "accept, x-requested-with, content-type",
            "Access-Control-Allow-Methods": "GET, OPTIONS",
            "Access-Control-Allow-Origin": req.headers.origin
        };
        if (req.method === "OPTIONS") {
            res.writeHead(204, headers);
            return res.end("OK");
        } else {
            res.writeHead(200, headers);
            return res.end("ALIVE");
        }
    });
    server = app.listen(8555);
    console.log("listening on 8555");
    return {
        stop: function(done) {
            var self = this;
            return server.close(done);
        }
    };
}).then(function(task){
  // make some http requests to the server
  // then stop the server
  task.stop(function(){
    console.log('stopped')
  })
})

PogoScript

PogoScript makes using censeo even better:

result = client.run! @{1+1}
expect(result).to.equal(2)

or to run a web server

task = client.runTask!()
  http    = require 'http'
  app = http.createServer @(req, res)
    headers = {
      'Content-Type'                  = 'text/plain'
      'Connection'                    = 'Close'
      'Access-Control-Allow-Headers'  = 'accept, x-requested-with, content-type'
      'Access-Control-Allow-Methods'  = 'GET, OPTIONS'
      'Access-Control-Allow-Origin'   = req.headers.origin
    }
    if (req.method == 'OPTIONS')
      res.writeHead(204, headers)
      res.end('OK')
    else
      res.writeHead(200, headers)
      res.end('ALIVE')

  server  = app.listen(8555)
  console.log "listening on 8555"
  {
    stop(done)=
      server.close(done)
  }

server url = 'http://localhost:8555'

response = request!({url = server url})
expect(response).to.equal('ALIVE')

task.stop!()