aliv

1.13.0 • Public • Published

Build Status Coverage Status npm version

It's alive! It's alive! In the name of God! Now I know what it feels like to be God! ~Frankenstein

What?

Light, fast and powerful one liner live-reloading Node.js server.

From the simplest live-reloading server to complex apps that need compression, proxies, middlewares and HTTP/2 - aliv got you covered.

Install

Globally:

$ npm i -g aliv

Locally:

$ npm i --save-dev aliv

Why?

Some similar modules out there are not as easy to setup, to maintain, or to extend. This one was made on demand for web development, more specific, to Single Page Applications. No more silly bugs when refreshing deep routes and then getting 404'd.

aliv simplifies a lot of headache we have when developing complex web apps.

  • Proxy request/responses;
  • Automagically gzip the response of your server;
  • Use HTTP/2 by simply setting http2 to true;
  • Refresh all your connected browsers with each file change;
  • Run a bunch of middlewares before each browser reload if you feel like it;
  • Use less memory/CPU possible.

How?

You can choose the way to work with aliv: CLI (terminal), aliv.config.js (Node module), .alivrc (config file) or a local node module.

Go to the folder that contains the index.html file and run:

$ aliv

There you go, all running!

Oh, do you want some specific stuff? Checkout the available options. If you need help with something more specific, feel free to check the wiki.

Options

Head over to the wiki to see all the options

CLI

--version, --v                   display version (only available on the CLI)
--port, --p                      change port
--host, --h                      change the host name
--secure, --s                    use https/wss
--http2, --h2                    use the new and improved version of the HTTP protocol
--cors, --c                      respond to requests with CORS headers, use true or object to override defaults
--quiet, --q                     no logging whatsoever
--noBrowser, --nb                won't open the browser automagically
--only, --o                      will only watch for changes in the given path/glob/regex/array
--ignore, --ign                  won't watch for changes in the given path (regex)
--pathIndex, --pi                change the path to your index.html
--proxy, --px                    uses proxy
--proxyTarget, --pxt             the http/https server where the proxy will "redirect"
--proxyWhen, --pxw               when the proxy should be activated; like --pxw /api/*
--root, --ro                     set the root to a different folder, like "./src/my/deep/folder/"
--watch, --w                     choose to watch for files change or not
--static, --st                   choose what paths are going to be served
--reloadDelay, --rd              time (in ms) to delay the browser refresh
--redirectHttpToHttps, --rhh     redirect any http traffic to https
--insecurePort, --insPort        inform an insecure port

aliv.config.js

All the options being used on the CLI can be added to the aliv.config.js file, like this:

module.exports = {
  port: 9999,
  quiet: true,
  cors: {
    headers: "Content-Type, Custom-Header",
    methods: "GET, OPTIONS",
    credentials: false
  },
  pathIndex: "src/",
  only: ["src/**/*"],
  proxy: true,
  proxyWhen: ["/api/*", "/cqrs/*"],
  proxyTarget: ["http://my-other-server.com:1234", "http://my-cqrs-server.com:1234"]
}

By doing that, when running $ aliv, it'll get all the options in aliv.config.js and use it.

But, if you have such file and still use something like $ aliv --port 9999, the cli will have priority over the file.

.alivrc

All the options being used on the CLI can be added to the .alivrc file, like this:

{
  "port": 9999,
  "quiet": true,
  "cors": {
    "headers": "Content-Type, Custom-Header",
    "methods": "GET, OPTIONS",
    "credentials": false
  },
  "pathIndex": "src/",
  "only": ["src/**/*"],
  "proxy": true,
  "proxyWhen": ["/api/*", "/cqrs/*"],
  "proxyTarget": ["http://my-other-server.com:1234", "http://my-cqrs-server.com:1234"]
}

By doing that, when running $ aliv, it'll get all the options in .alivrc and use it.

But, if you have such file and still use something like $ aliv --port 9999, the cli will have priority over the file.

Node module

const Server = require('aliv');
 
// yes, that easy - now your browser will open
// and it'll be refreshed every time a file changes
new Server({quiet: true}).start();

Default values

--port                  is 1307
--host                  is 127.0.0.1
--secure                is false
--http2                 is false
--cors                  is false
--quiet                 is false
--only                  is ".", which means it'll watch everything
--ignore                see list full regex in lib/options.js
--noBrowser             is false, which means it'll always open the browser on start
--pathIndex             is "", which means it'll look for the index.html in the root
--proxy                 is false, which means it'll not look for another server to answer for the /api/, for example
--proxyTarget           is "", no server to be target
--proxyWhen             is "", and it's supposed to be set with something like /api/*
--root                  is process.cwd()
--watch                 is true
--static                is [root, root + "/path/to/your/index"]
--reloadDelay           is 0
--redirectHttpToHttps   is false
--insecurePort          is 80

Wiki

Check the wiki for examples, FAQ, available options, troubleshooting and more.

Contributing

I've got an idea!

Great, let's talk!

I want to contribute

Awesome!

First, I'd suggest you open an issue so we can talk about the changes to be made and suchs and then you can do whatever you want 😄

Also, there's the folder _fixture ready to be customized so you can try some stuff while modifying the code; just run npm start and have fun!

License

MIT

Package Sidebar

Install

npm i aliv

Weekly Downloads

32

Version

1.13.0

License

MIT

Unpacked Size

29.1 kB

Total Files

18

Last publish

Collaborators

  • ericmdantas