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

console-log-server

v0.3.0

Published

Logs all http requests to console

Downloads

8

Readme

console-log-server

Logs all requests to command line console (stdout) and responds 200 OK.

Useful for quickly viewing what kind of requests your app is sending.

Usage

If you have npm >= v5.2 (comes bundled with node >= v8.2.0) you can use npx to run it directly:

$ npx console-log-server -p 8000

If you have older node (all version >= v0.10 supported!) or just prefer the old fashioned way:

$ npm install console-log-server --global
$ console-log-server -p 8000

Command line options

  Logs all http requests to console

  Usage
    $ console-log-server

  Options
    --port, -p Port Number
    --hostname, -h Host name. You can provide multiple hostname flags (with optional matching port flags) to listen many hostnames. 
    --proxy, -P Host(s) to proxy the request to using https://www.npmjs.com/package/express-http-proxy. Syntax: [<path>>]<url>. You can provide different proxies for separate paths.
    --response-code, -c Response response code (ignored if proxied)
    --response-body, -b Response content (ignored if proxied)
    --response-header, -H Response header (ignored if proxied)
    --log-response, -r Log also the response. Enabled by default only for proxied requests. Logged response is fully read to a buffer which might change your api behaviour since response is not streamed directly to client, consider turning off if that is a problem.
    --no-color
    --version
    --date-format, -d Date format supported by https://www.npmjs.com/package/dateformat (default "yyyy-mm-dd'T'HH:MM:sso")
    --help
    --default-cors, -C Add "default" cors using https://www.npmjs.com/package/cors default values. By default only enabled for non-proxied responses. Turn on to enable also for proxy responses, turn off to disable completely.

  Examples

    # basic usage
    $ console-log-server -p 3000

    # customized response
    $ console-log-server -p 3000 -c 201 -b "cool type content" --response-header='Content-Type:application/cool' --response-header='key:value'

    # Log date with UTC date format instead of local with offset
    $ console-log-server -d "isoUtcDateTime"

    # Proxy the request to other host. Response will be the actual response from the proxy. 
    $ console-log-server -P http://api.example.com

    # Proxy the requests to multiple hosts based on paths.
    $ console-log-server --proxy="/api/1>http://api-1.example.com" --proxy="/api/2>http://api-2.example.com"

    # Proxy the request to path under other host. Response will be the actual response (with cors headers injected) from the proxy.
    $ console-log-server -P http://api.example.com/v1/cats -C yes

    # Turn off response logging
    $ console-log-server -r no

    # Turn on response logging for all requests
    $ console-log-server -r yes

    # Don't add default (allow all) cors headers at all
    $ console-log-server -C no

    # Start server to your local IP and localhost. Might be useful when debugging devices connected to your own machine. Ports can be given for each hostname with --port flag(s).
    $ console-log-server -h localhost -h 192.168.0.2 

Legacy Node.js support

Are you stuck with old unmaintained node.js version filled with security holes? You know you should upgrade, but you have your reasons. Don't worry, console-log-server is not here to judge, but to help (although you should really upgrade and definitely not run anything unmaintained in production, so judging a little bit here).

Currently all node.js version >= v0.10 are supported. This is done by transpiling to ES5 using babel and requiring core-js for missing types on standalone mode.

Development/forking/building of console-log-server itself requires node >= v10 though and you should always use latest stable node for that.

Only for debugging/development use

Only use this tool for ad-hoc local testing. NEVER run console-log-server in production for multiple reasons:

  • It logs all data as is without filters. Including passwords, tokens, user names etc
  • It will make performance lot worse
  • It might use old/deprecated libraries or node.js version with vulnerabilities

Library use

If you are using console-log-serveras a library and use very old node without newer JS types like Map or Promise you need to polyfill them. Otherwise you get errors like:

"ReferenceError: Promise is not defined"

This is mainly problem with node 0.10 but you could in theory get some errors with node < v6.

Easiest way to fix these is to just load core-js before console-log-server

require('core-js');
var consoleLogServer = require('console-log-server');