A Node.JS static server module with built-in cache options and route features.
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.
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.");
});
There are few ways to get help:
- Please post questions on Stack Overflow. You can open issues with questions, as long you add a link to your Stack Overflow question.
- For bug reports and feature requests, open issues. π
- For direct and quick help, you can use Codementor. π
For full API reference, see the DOCUMENTATION.md file.
Have an idea? Found a bug? See how to contribute.
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 π
-
βI love books! I will remember you after years if you buy me one. π π
-
βYou can make one-time donations via PayPal. I'll probably buy a
coffeetea. π΅ -
β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! β€οΈ
If you are using this library in one of your projects, add it in this list. β¨
xhr-form-submitter-test
bac-results