Skip to content
This repository has been archived by the owner on May 3, 2022. It is now read-only.

Commit

Permalink
Tweak docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Jan 14, 2018
1 parent 1c7f9cc commit e1a164a
Showing 1 changed file with 108 additions and 43 deletions.
151 changes: 108 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,54 +16,35 @@

> Hot Module replacement (HMR) capabilities for any HTTP Server.
The idea behind this project is **smart reload**, avoiding reload completely the process. It just reload the code that changes!

It's similar [micro-dev](https://github.com/zeit/micro-dev), but out of the box for any framework that use [http.Server.listen()](https://nodejs.org/api/http.html#http_server_listen_port_hostname_backlog_callback) interface.

## Install
## Installation

You can install it as global

```bash
$ npm install svr --save-dev
$ npm install svr --global
```

## Usage

### Development

The only requirement is define the main file of your server as exported function that follow this interface:
Or use it as part of your development workflow as a `devDependency`:

```js
module.exports = (app, express) => {
/* your awesome code here */
}
```bash
$ npm install svr --save-dev
```

This could be a good start point for a HTTP server:
## Usage

```js
const isProduction = process.env.NODE_ENV === 'production'
### Getting Started

module.exports = (app, express) => {
/* here you can do whatever you want */
app
.use(require('helmet')())
.use(require('compression')())
.use(require('cors')())
.use(require('jsendp')())
.use(require('express-status-monitor')())
.use(bodyParser.urlencoded({ extended: true }))
.use(bodyParser.json())
.use(require('morgan')(isProduction ? 'combined' : 'dev'))
.use(express.static('static'))
.disable('x-powered-by')
After installation, just call it:

app.get('/', async function (req, res) {
return res.send('hello world')
})

return app
}
```bash
$ svr
```

After that, you need to call `svr`. We recommend add `svr` as npm script:
We recommend add **svr** as npm script:

```json
{
Expand All @@ -73,7 +54,7 @@ After that, you need to call `svr`. We recommend add `svr` as npm script:
}
```

Running `npm run dev` you start your HRM development server:
Now, running `npm run dev` it will be start your HRM development server:

```bash
$ npm start
Expand All @@ -88,9 +69,33 @@ $ npm start
└───────────────────────────────────────────────────┘
```

`svr` it's assuming main file is called `index.js` in the current path. Otherwise, you can provide the file path as first argument.
**svr** is assuming you have a `main` file declared in your `package.json` in the project directory.

Now whatever file modification in the current directory is listened by the `svr` automagically:
Otherwise, you can provide the file path as first argument:

```bash
$ svr src/server/routes.js
```

The only requirement is define the main file of your server as exported function that follow this interface:

```js
module.exports = (app, express) => {
/* your awesome code here */
}
```

If your project directory is different from the current directory you can specify it as well using `-d` or `--cwd` flag:

```bash
$ svr src/server/routes.js --cwd=~/Projects/my-express-api
```

Type `svr --help` to get all the information.

### Watching for changes

After start, whatever file modification in the project directory will be listened by **svr** automagically:

```bash
┌───────────────────────────────────────────────────┐
Expand All @@ -105,9 +110,7 @@ Now whatever file modification in the current directory is listened by the `svr`
ℹ 18:32:42 modified index.js
```

It takes in consideration your `.gitignore` files, so it only will reload the right files.

Using `svr --watch` you can add more files to be watched, but you need to reload the server in any time, just type `rs`:
If you need to reload the server on demand, just type `rs`:

```bash
┌───────────────────────────────────────────────────┐
Expand All @@ -124,9 +127,71 @@ Using `svr --watch` you can add more files to be watched, but you need to reload
ℹ 18:34:07 restart index.js
```

### Production
**svr** only will be listen files in the current directory by default.

You can use `-w` or `--watch` to add more file path to be listened

```bash
$ svr src/server/routes.js
```

Type `svr --help` to get all the information.

### Ignoring files

**svr** takes into consideration ignore non relevant files.

By default, it will be to ignore:

- well known files to ignore, like `node_modules`, `.git`, etc.
- `.gitignore` declarations.
- `ignored` field in your `package.json`.

You can declare:

- Relative or absolute paths.
- Glob patterns.

If you need to add a specific file to ignore, use `i` or `--ignore` flag:

```bash
$ svr -i .cache -i public
```

## Tips

### Development Server

This could be a good start point for a HTTP server:

```js
const isProduction = process.env.NODE_ENV === 'production'

module.exports = (app, express) => {
/* here you can do whatever you want */
app
.use(require('helmet')())
.use(require('compression')())
.use(require('cors')())
.use(require('jsendp')())
.use(require('express-status-monitor')())
.use(bodyParser.urlencoded({ extended: true }))
.use(bodyParser.json())
.use(require('morgan')(isProduction ? 'combined' : 'dev'))
.use(express.static('static'))
.disable('x-powered-by')

app.get('/', async function (req, res) {
return res.send('hello world')
})

return app
}
```

### Production Server

`svr` is oriented for development scenario.
**svr** is oriented just for development scenarios.

Under production, simply create the boostraping server that you need.

Expand Down Expand Up @@ -159,7 +224,7 @@ Just add it as `npm start` script
}
```

That's all. You're taking the best of the two worlds: Developer Experience for development and tiny bundle for production.
That's all.

## License

Expand Down

0 comments on commit e1a164a

Please sign in to comment.