Coder Social home page Coder Social logo

netsi1964 / tiny-node.js-webserver Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rodw/tiny-node.js-webserver

0.0 2.0 0.0 107 KB

A simple, standalone, single-file web server for static files implemented with node.js and CoffeeScript.

License: Other

tiny-node.js-webserver's Introduction

a tiny node.js webserver

What is it?

The tiny node.js webserver (hereafter, "tnws") is just that, a simple webserver implemented as a single, stand-alone CoffeeScript (or JavaScript) file.

By design, the tnws has no external dependencies outside of the core node.js libaries (and CoffeeScript, unless you're working with the "compiled" JS file).

There are many other simple node.js applications for serving static files over HTTP, however the tnws is the only one I know of meets the "all-in-one-file" criterion.

Why is it?

Sometimes you just need a little webserver.

Specifically, web browsers often treat resources served from local file:// URLs slightly differently those served via http:// URLs. The tnws offers a quick-and-dirty way to serve local files over HTTP, which can come in handy when developing web applications based on local HTTP/JS/CSS files, etc.

How do I use it?

Just fetch the tnws.coffee file:

curl -O https://raw.github.com/rodw/tiny-node.js-webserver/master/tnws.coffee

(or otherwise download the file at this url).

And run it:

coffee tnws.coffee

or simply:

./tnws.coffee

That's all. The tnws should now be listening at port 8080 on your localhost. For example, you can fetch the twns.coffee source code itself by visiting http://localhost:8080/tnws.coffee.

Installing TNWS in Your Path

If you use the tiny node.js webserver often, you may want to install it somewhere in your $PATH.

For instance, if the directory ~/bin exists and is in your path, then you can save tnws.coffee into that directory:

curl -o "~/bin/tnws" https://raw.github.com/rodw/tiny-node.js-webserver/master/tnws.coffee

and thereafter, launch a web server instance serving files from the current directory with just tnws.

Options

The tnws can be configured through a few simple command-line arguments.

In full:

tnws --port <port> --host <host> --docroot <docroot> \
     --index <filename> --mime-type <ext> <value> \
     --quiet --silent

where:

  • --host or -h specifies the hostname to bind to (defaults to 127.0.0.1).
  • --port or -p specifies the port to listen on (defaults to 8080).
  • --docroot or -d specifies the directory from which to serve files (defaults to .).
  • --index or -i specifies the file to serve when a directory is requested (defaults to index.html).
  • --mime-type or -m specifies that files with the extension <ext> should be served with the MIME type <value>. Note that you can repeat the --mime-type flag to specify multiple mappings.
  • --quiet or -q supresses the <STATUS-CODE> <REQUEST-METHOD> <REQUEST-URI> log messages that tnws otherwise generates for every request serviced.
  • --silent or -s supresses all non-error console messages. (Note that --silent implies --quiet.)

These arguments are all optional.

Licensing

The tnws is distributed under the MIT License, as specified in LICENSE.txt and in the tnws.coffee file itself.

tiny-node.js-webserver's People

Contributors

rodw avatar

Watchers

Sten Hougaard avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.