# @wfh/express-app

> Work with Plink, base Express app

Latest version **1.1.11** (published 2021-10-10) · 0 weekly downloads

## Install

```sh
npm install @wfh/express-app
pnpm add @wfh/express-app
yarn add @wfh/express-app
bun add @wfh/express-app
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.11 |
| Published | 2021-10-10 |
| First published | 2020-09-27 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 10 |
| Unpacked size | 58.3 KB |
| Known vulnerabilities | 0 (+2 in 1 direct dependencies) |
| Install scripts | no |
| Author | LJ |
| Maintainers | liujingbreak |

## Links

- npm: https://www.npmjs.com/package/@wfh/express-app
- npm.io page: https://npm.io/package/@wfh/express-app

## Dependencies (10)

- [cors](https://npm.io/package/cors.md) ^2.8.5
- [rxjs](https://npm.io/package/rxjs.md) ~6.4.0
- [lodash](https://npm.io/package/lodash.md) ^4.17.21
- [express](https://npm.io/package/express.md) ^4.17.1
- [@types/cors](https://npm.io/package/@types/cors.md) ^2.8.9
- [body-parser](https://npm.io/package/body-parser.md) ~1.18.1
- [compression](https://npm.io/package/compression.md) ^1.7.0
- [consolidate](https://npm.io/package/consolidate.md) ^0.14.5
- [cookie-parser](https://npm.io/package/cookie-parser.md) ~1.4.3
- [@types/body-parser](https://npm.io/package/@types/body-parser.md) ~1.17.0

## Recent versions

- 1.1.11 (latest) — 2021-10-10
- 1.1.10 — 2021-03-29
- 1.1.8 — 2020-10-12
- 1.1.7 — 2020-09-27

## README

Express server
==========

This package contains Express web framework as core package.
Also this package is API provider.

### Supported Express middlewares
You don't need to add following middleware, they have already been onboard.
- #### cookie-parser
- #### body-parser
- #### compression

### new API

New Node API methods
| Name | description
|-- | --
| .router() | return an Express Router object
| .use() | Express use() method, to bind middleware
| .param() | Express param() method
| .expressAppSet(callback) | callback: function(app, express), whatever things you want to do before express's app getting initialized
| .swig | express view engines: `require('swig-template')`
| .express | express instance, so that you can access some express middleware, like `api.express.static`
| .expressApp | the main express app instance used by us, which is value of `express()`
| .cors() | CORS middleware for specific route path, e.g. `api.router().use('/api', api.cors());`
check [setupApi.js](setupApi.js)

Above API methods must be called within `module.exports.activate()` function
e.g.
```javascript
var api = require('__api');

exports.activate = function() {
	api.router().get(function(req, res) {
		res.render('/template.html');
	});
};

```

e.g. expressAppSet(callback)
```js
exports.activate = function(){
 	api.expressAppSet((app, express) => {
 		app.set('trust proxy', true);
		app.set('views', Path.resolve(__dirname, 'web/views/'));
	});
};
```

# Check server side git hash
You need put generate a git hash text file in root folder like,
```bash
git rev-parse HEAD > githash-server.txt
echo \"I am in Dev\" >> githash-server.txt
```

Or put in your package.json npm script:
```js
"scripts": {
	"build": "git rev-parse HEAD > githash-server.txt && echo \"I am in Dev\" >> githash-server.txt:
}
```

Once your start server by `node app`, you can access `/githash-server` or `/githash-server.txt`

---
_Source: https://npm.io/package/@wfh/express-app · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
