Skip to content

🔮 A Node.JS static server module with built-in cache options and route features.

License

Notifications You must be signed in to change notification settings

IonicaBizau/statique

Repository files navigation

statique

$ statique

Support me on Patreon Buy me a book PayPal Ask me anything Travis Version Downloads Get help on Codementor

Buy Me A Coffee

A Node.JS static server module with built-in cache options and route features.

☁️ Installation

You can install the package globally and use it as command line tool:

# Using npm
npm install --global statique

# Using yarn
yarn global add statique

Then, run statique --help and see what the CLI tool can do.

$ statique --help
Usage: statique [options]

A Node.JS static server module with built-in cache options and route features.

Options:
  -p, --port <port>    The port where the server will run.
  -c, --cache <cache>  The cache value in seconds.
  -r, --root <root>    The server public directory.
  -h, --help           Displays this help.
  -v, --version        Displays version information.

Examples:
  $ statique # opens the server on port 9000 serving files from the current dir
  $ statique -p 5000 -r path/to/public -c 0 # without cache

Documentation can be found at https://github.com/IonicaBizau/statique.

📋 Example

Here is an example how to use this package as library. To install it locally, as library, you can use npm install statique (or yarn add statique):

// Dependencies
var Statique = require("statique/lib/index")
  , Http = require('http')
  ;

// Create *Le Statique* server
var server = new Statique({
    root: __dirname + "/public"
  , cache: 36000
}).setRoutes({
    "/": "/html/index.html"
  , "/test1/": { get: "/html/test1.html" }
  , "/test2": "/html/test2.html"
  , "/some/api": function (req, res) {
        res.end("Hello World!");
    }
  , "/buffer": function (req, res) {
        server.sendRes(res, 200, "text/plain", new Buffer("I am a buffer."));
    }
  , "/some/test1-alias": function (req, res) {
        server.serveRoute("/test1", req, res);
    }
  , "/method-test": {
        get: function (req, res) { res.end("GET"); }
      , post: function (req, res, form) {
            form.on("done", function (form) {
                console.log(form.data);
            });
            res.end();
        }
    }
  , "/crash": {
        get: function (req, res) { undefined.something; }
    }
  , "/anynumber-[0-9]": {
        re: true
      , handler: function (req, res) {
            res.end("Hi");
        }
    }
  , "r1": {
        re: /anyletter\-[a-z]/i
      , handler: function (req, res) {
            res.end("Case insensitive is important. ;)");
        }
    }
}).setErrors({
    404: "/html/errors/404.html"
  , 500: "/html/errors/500.html"
});

// create server
Http.createServer(server.serve.bind(server)).listen(8000, function (err) {
    // Output
    console.log("Listening on 8000.");
});

❓ Get Help

There are few ways to get help:

  1. Please post questions on Stack Overflow. You can open issues with questions, as long you add a link to your Stack Overflow question.
  2. For bug reports and feature requests, open issues. 🐛
  3. For direct and quick help, you can use Codementor. 🚀

📝 Documentation

For full API reference, see the DOCUMENTATION.md file.

😋 How to contribute

Have an idea? Found a bug? See how to contribute.

💖 Support my projects

I open-source almost everything I can, and I try to reply to everyone needing help using these projects. Obviously, this takes time. You can integrate and use these projects in your applications for free! You can even change the source code and redistribute (even resell it).

However, if you get some profit from this or just want to encourage me to continue creating stuff, there are few ways you can do it:

  • Starring and sharing the projects you like 🚀

  • Buy me a book—I love books! I will remember you after years if you buy me one. 😁 📖

  • PayPal—You can make one-time donations via PayPal. I'll probably buy a coffee tea. 🍵

  • Support me on Patreon—Set up a recurring monthly donation and you will get interesting news about what I'm doing (things that I don't share with everyone).

  • Bitcoin—You can send me bitcoins at this address (or scanning the code below): 1P9BRsmazNQcuyTxEqveUsnf5CERdq35V6

Thanks! ❤️

💫 Where is this library used?

If you are using this library in one of your projects, add it in this list. ✨

  • xhr-form-submitter-test
  • bac-results

📜 License

MIT © Ionică Bizău

About

🔮 A Node.JS static server module with built-in cache options and route features.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published