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

node-web-server

v1.1.4

Published

Node.js Web Server

Downloads

48

Readme

node-web-server NPM Version Build Status Coverage Status

PC 上で簡単に導入できる簡易的な静的ファイル用 Web サーバです。

※ 本番環境で動作させることは考慮されていません。

Installation

$ npm install -g node-web-server

Usage

Command line

$ nws -h
node-web-server command line interface

Usage: nws [options]

Options:
  -h             print this help
  -v             print node-web-server's version
  -d [http.conf] copy default config file
  -c [http.conf] load config file & run server
  host:port      run server at host:port

Script

nws.run(settings(string or object), [current_directory]);

settings は設定ファイルのパスまたは設定を直接objectで指定します。 current_directory を指定すると、そのディレクトリを基準にした相対パスでドキュメントルート とログファイルの保存先が設定されます。

example.js

var nws = require('node-web-server');
// 起動 (__dirname を current directory として localhost:8080 で起動)
  nws.run({
    host: "localhost",
    port: 8080,
    docRoot: "www"
  }, __dirname);
// 10秒後に停止
setTimeout(nws.stop, 10000);

Configuration

/lib/http.conf

{
  "host"       : ホスト名 or IPアドレス or 環境変数 (process.env.*),
  "port"       : ポート番号 or 環境変数 (process.env.*),
  "docRoot"    : ドキュメントルート (相対パス),
  "defFile"    : [
    デフォルトのインデックスファイル
  ],
  "accessLog"  : HTTP リクエストのログファイル (相対パス) or false,
  "errorLog"   : エラー発生時のログファイル (相対パス) or false,
  "httpHeaders": {
    HTTPヘッダー
  },
  "allowUnknownMIMEType": MIMEType が一致しない場合に application/octet-stream で転送することを許可します true or false,
  "MIME"      : {
    MIMEタイプ
  }
}

ex. Cloud Foundry

{
  "host"      : "0.0.0.0",
  "port"      : "process.env.VCAP_APP_PORT || 3000",
  <The rest is omitted>

ex. Heroku

{
  "host"      : "0.0.0.0",
  "port"      : "process.env.PORT || 3000",
  <The rest is omitted>

'||' 演算子を使うことができます。 You can use '||' operator.

Logging

ログは下記のように記録されます (アクセスログの例)

{ "date":"Fri, Sep 30 2011 20:26:11 GMT-0900", "method":"GET", "url":"/", "statusCode":200 } ,{ "date":"Fri, Sep 30 2011 20:26:11 GMT-0900", "method":"GET", "url":"style.css", "statusCode":200 }

これを [] で囲むことで、JavaScriptの配列として読み込むことが出来ます。

var obj = JSON.parse("[" + log + "]");

Testing

npm test

Coverage (blanket)

mocha -r blanket -R html-cov > coverage.html

Coverage (istanbul)

istanbul cover ./node_modules/mocha/bin/_mocha

Changelog

v1.1.4: 2015/03/26

  • Node.js v0.12 対応
  • io.js 対応
  • v0.6 対応切り捨て

v1.1.3: 2014/05/25

  • デフォルトで access.log を出力しないようになりました。
  • テストを追加しました。
  • allowUnknownMIMEType オプションを追加しました。

v1.1.2: 2012/07/15

  • README の間違いを訂正しました。
  • 相対パスの扱いを修正しました。
  • node v0.8 に対応しました。

v1.1.1: 2012/03/27

  • 改行コードを CRLF から LF に変更しました。
  • Linux で nws コマンドが使えない問題を解決しました。

v1.1.0: 2012/03/25

  • モジュール化し、他のアプリに組み込めるようにしました。
  • #4 コマンドラインからの実行も可能。

v1.0.9: 2012/02/07

  • fix #3 URL 周りのバグを修正しました。

v1.0.8: 2012/01/22

  • Date Format の間違いを修正しました。

v1.0.7: 2012/01/15

  • fix #1 URL の扱いを改善しました。
  • access.log が生成されないバグを改善しました。

v1.0.6: 2011/12/19

  • Settings File でホスティングサービスの環境変数 (process.env.*) に対応。

v1.0.5: 2011/11/12

  • Date format (RFC1123) の修正。

v1.0.4: 2011/10/07

  • デフォルトインデックス (defFile) 部分の修正。

v1.0.3: 2011/09/30

  • ロギング部分の修正。

v1.0.2: 2011/09/26

  • エラーメッセージにドキュメントルートのフルパスが表示される脆弱性を修正。

v1.0.1: 2011/09/02

  • bugfix

v1.0.0: 2011/08/11

  • Release