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

takeout

v0.3.0

Published

Get the file contents, seamlessly available for both local file system and HTTP(S)

Downloads

13

Readme

takeout

Build Status Build status Coverage Status Dependency Status devDependency Status

A Node module to get the file contents, seamlessly available for both local file system and HTTP(S)

var takeout = require('takeout');

// Reading a local file
takeout('path/to/local/file', {encoding: 'utf8'}, function(err, body) {
  if (err) {
    throw err;
  }
  
  console.log(body);
});

// GET request if the location is URL
takeout('http://nodejs.org', {encoding: 'utf8'}, function(err, body, res) {
  if (err) {
    throw err;
  }

  console.log(res.statusCode);
  console.log(body);
});

Installation

NPM version

Use npm.

npm install takeout

API

var takeout = require('takeout');

takeout(location,[ options,] callback)

location: String (local file path or URL)
options: Object
callback: Function

If the location is a local file path, it reads the file with fs.readFile. If the locatiandon is a URL, it makes a GET request to the URL and grabs its response, using got.

// `http` and `https` scheme is optional.
takeout('www.npmjs.org', function(err, body, res) {
  if (err) {
    throw err;
  }

  console.log(res.statusCode);
  console.log(body);
});

options

In addition to the following, all options for fs.readFile and got are available.

options.encoding

Type: String or null
Default: null (In other words, the content is returned as a Buffer by default.)

Directly passed to fs.readFile options or setEncoding of the response data.

options.directoryIndex

Type: Boolean or String of filename
Default: index.html

When the path indicates a local directory, it reads index.html or a file with the specified filename immediately under the directory.

false disables this feature.

// |
// +- dist
//     +- index.html ('foo')
//     +- home.html ('bar')

takeout('dist', function(err, buf) {
  !err; //=> true
  buf.toString(); //=> 'foo'
});

takeout('dist', {directoryIndex: 'home.html'}, function(err, buf) {
  !err; //=> true
  buf.toString(); //=> 'bar'
});

takeout('dist', {directoryIndex: false}, function(err) {
  err.code; //=> 'ENOTFOUND'
});

callback(error, body, response)

error: Error if it fails to get the contents, otherwise null
body: Buffer or String (according to options.encoding)
response: Object (response object) if the content is got via HTTP(S), otherwise undefined

CLI

You can use this module as a CLI tool by installing it globally.

npm install -g takeout

Usage

Usage1: takeout <file path | URL> --out <dest>
Usage2: takeout <file path | URL> > <dest>

Options:
--out,      -o <file path>   Write the result to a file (stdout by default)
--encoding, -e <encoding>    Set encoding (same as Node's encoding option)
--index,    -d <filename>    Set the filename of directory index
--no-index,                  Do not care about directory index
--timeout,  -t <ms>          Set time after which the request will be aborted
--help,     -h               Print usage information
--version,  -v               Print version

You can do almost the same thing with cat and curl. But this tool works on various environments, as long as they supports Node.

License

Copyright (c) 2014 Shinnosuke Watanabe

Licensed under the MIT License.