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

jaqen

v1.0.0

Published

Testing server to programmatically test API dependant scripts.

Downloads

3

Readme

Jaqen

Jaqen is a minimal server to which you can programmatically instruct what to respond within the very request, allowing to easily test API dependant scripts.

Quick example:

# Console request to a Jaqen instance listening at localhost:9000
$ curl 'http://localhost:9000/echo.json?foo=bar&data\[name\]=Jaqen&data\[v\]=1.0.0'
=> {"foo":"bar","data":{"name":"Jaqen","v":"1.0.0"}}

With just /echo.json we told Jaqen to return the request data (the URL's query in this case) as JSON, not hard at all.

Features

  • Echo: Returns the very data from the request converted accordingly (as JSON, text, etc.).

  • RESTful API: Rather than handling HTTP verbs, Jaqen responds the same independently of the verb, so you can simulate any kind of API.

  • Build files on the fly: Set the response body and it will return it untouched with the right MIME type.

  • Serve static files: If a request doesn't match any of the 'echo' types Jaqen will attempt to serve static files from the directory where it's running.

  • MIME types: For any request, Jaqen will set the Content-Type header according to the extension on the pathname (.json, .txt, .html, etc.).

Installation

$ npm install -g jaqen

Running Jaqen

To run Jaqen just type jaqen in the console:

$ jaqen
=> Jaqen is listening on port 9000.
=> Press Ctl+C to stop the server.

Now Jaqen should be listening at port 9000, to test it's running visit this address with your browser: http://localhost:9000/echo.json?msg=Hello%20World!. You should see this: {"msg":"Hello World!"}

Options

Jaqen accepts only one option, the port where it should be listening. By default it uses port 9000, to change it use the --port or -p flags:

$ jaqen -p 5000
=> Jaqen is listening on port 5000.
=> Press Ctl+C to stop the server.

Static files server

Jaqen also serves static files from the folder where you run it, useful to load test pages and their assets. If you need some files, first move to the folder where the files are located and then run Jaqen from there.

$ cd path/to/files_folder
$ jaqen
=> Jaqen is listening on port 9000.
=> Press Ctl+C to stop the server.

Now you can access any file in files_folder. For example, if you have something like tests/index.html inside that folder, visit localhost:9000/tests on your browser to see it.

API

Static files aside, there are three ways to programmatically instruct Jaqen what to respond:

  • Echo:

    If the pathname in the request begins with echo (/echo, /echo.json, /echo/something.json, etc.), Jaqen mirrors the data from both the request body (POST data) and the URL query (GET data). If there are conflicts the data from the URL query overrides the one from the request body (non-deep merge).

    # '-d' -> make a POST request with the specified data.
    $ curl 'http://localhost:9000/echo.json?id=3' -d 'id=null&title=Lorem%20ipsum'
    => {"id":"3","title":"Lorem ipsum"}

    Here the 'id' in the URL query overrides the 'id' of the POST data.

  • Query:

    If the pathname begins with query (/query, /query.json, /query/something.json, etc.). It's similar to the previous one but responds with just the data from the URL query ignoring the request body.

    $ curl 'http://localhost:9000/query.json?status=success&id=5'
    => {"status":"success","id":"5"}

    Specially useful to test POST request over AJAX that expect a response.

  • Setting the response body:

    If there's a _responseBody param (either on the URL query or in the request body) Jaqen will return the data from that parameter untouched and will set the right MIME type according to the extension on the pathname (e.g. .html)

    # '-i' -> include the headers in the output.
    # '-d' -> make a POST request with the specified data.
    $ curl 'http://localhost:9000/echo.html' -i \
            -d '_responseBody=<html><body><h1>Jaqen!<h1></body></html>'
    => HTTP/1.1 200 OK
    => Content-Type: text/html
    ...
    => <html><body><h1>Jaqen!<h1></body></html>

    It responds exactly the value of '_responseBody' and sets the right content type, it's like creating a file on the fly.

License

Jaqen is dual licensed under the MIT or GPLv3 licenses.

Contributing

If you find a bug or have good ideas about how to improve this implementation you are welcome to open an issue or make a pull request with a feature branch.