UNPKG

7.71 kBMarkdownView Raw
1# Node.js Express restful JSON API seed
2
3[![npm version](https://badge.fury.io/js/nodejs-restful-jsonapi-seed.svg)](https://badge.fury.io/js/nodejs-restful-jsonapi-seed) [![](https://img.shields.io/npm/dm/nodejs-restful-jsonapi-seed.svg)](https://www.npmjs.com/package/nodejs-restful-jsonapi-seed) [![Build Status](https://travis-ci.org/nuxy/nodejs-restful-jsonapi-seed.svg?branch=master)](https://travis-ci.org/nuxy/nodejs-restful-jsonapi-seed)
4
5Everything you need to start building a scalable web application.
6
7![the "seed" app](https://raw.githubusercontent.com/nuxy/nodejs-restful-jsonapi-seed/master/package.png)
8
9## Features
10
11- ECMAScript 2015 (ES6) compatible.
12- RESTful application interface.
13- JSON API standard request/responses.
14- ABAC (Attribute-Based Access Control)
15- HTTP/1/2 and SSL support.
16- Database driver support.
17- Session handling using cookies.
18- Schema-based validation.
19- Stream-based logging and file rotation.
20- Production process manager.
21- ESDoc App/Swagger API documentation.
22- Deployable as a Docker service.
23
24## Dependencies
25
26- [Node.js](https://nodejs.org)
27- [Docker](https://docker.com) (optional)
28
29## Installation
30
31### seed-cli
32
33Install the command-line utility using [NPM](https://npmjs.com).
34
35 $ npm install -g nodejs-restful-jsonapi-seed
36 $ seed-cli --help
37
38 Usage: seed-cli [options]
39
40 Options:
41 --create <project-name> Create a new seed example project
42 --build Transpile ES6 sources (using Babel) to a distribution
43 --start Launch a single server instance from a transpiled distribution
44 --deploy Launch a server cluster from a transpiled distribution
45 --watch Launch the server (development mode)
46 --lint Run ESLint on project sources
47 --test Run Mocha integration tests
48 --docker Deploy your application as a Docker service
49 --gendoc Generate documentation using ESDoc
50 --env <environment> Set the NODE_ENV (default: development)
51 -h, --help output usage information
52
53### Manual
54
55Clone the repository, or download the latest [release](https://github.com/nuxy/nodejs-restful-jsonapi-seed/releases).
56
57 $ git clone https://github.com/nuxy/nodejs-restful-jsonapi-seed.git
58
59Install package dependencies using [NPM](https://npmjs.com).
60
61 $ npm install
62
63## Developers
64
65While `seed-cli` provided with this package can execute NPM scripts, it's not a requirement. You can also achieve this using [npm-run-script](https://docs.npmjs.com/cli/run-script).
66
67### CLI options
68
69Set your environment. If `NODE_ENV` is not defined, the default config `development` is used.
70
71 $ export NODE_ENV=<production|staging|qa>
72
73Transpile ES6 sources (using [Babel](https://babeljs.io)) to a distribution:
74
75 $ npm run build
76
77Launch a _single server instance_ from a transpiled distribution:
78
79 $ npm run start
80
81Launch a _server cluster_ from a transpiled distribution:
82
83 $ npm run deploy
84
85Launch the server (development mode) with [nodemon](https://nodemon.io):
86
87 $ npm run watch
88
89Run [ESLint](https://eslint.org/) on project sources:
90
91 $ npm run lint
92
93Run [Mocha](https://mochajs.org) integration tests:
94
95 $ npm run test
96
97Deploy your application as a [Docker](https://docker.com) service:
98
99 $ npm run docker
100
101Generate documentation using [ESDoc](https://esdoc.org):
102
103 $ npm run gendoc
104
105## API Examples
106
107The following [routes](src/routes/examples) have been enabled in the application. When the server is running in _development_ mode [Swagger](https://swagger.io) generated documentation can be accessed at: [http://localhost:3000/api-doc](http://localhost:3000/api-doc)
108
109## Documentation
110
111When the server is running in _development_ mode [ESDoc](https://esdoc.org) generated documentation can be accessed at: [http://localhost:3000/app-doc](http://localhost:3000/app-doc)
112
113## Enabling HTTP/2
114
115The [http2](https://nodejs.org/api/http2.html) module is an experimental API which relies on the [Latest Current Version](https://nodejs.org/en/download/current) of Node.js to work. Furthermore, since there are no browsers known that support unencrypted HTTP/2, the use of [X.509 certificates](https://en.wikipedia.org/wiki/X.509) is necessary when communicating with browser clients.
116
117To set-up the server, first you must generate the certificate and key files:
118
119 $ openssl req -x509 -newkey rsa:2048 -nodes -sha256 -keyout localhost-key.pem -out localhost-cert.pem
120
121See the [Node.js documentation](https://nodejs.org/api/http2.html#http2_client_side_example) for information regarding client-side set-up.
122
123## SSL configuration
124
125Depending on your application requirements there are multiple ways to set-up the [server config](https://github.com/nuxy/nodejs-restful-jsonapi-seed/blob/master/config/default.json#L49):
126
127### Absolute path
128
129If your certificates are installed in a location outside of the application scope (e.g. `/etc/ssl/certs`), and your application has the permissions to access these files, you can add the _absolute path_ to the respective configuration values.
130
131### String output
132
133If, for whatever reason, you cannot host the certificates locally (shared environment), you can output each file as a newline-delimited string using the following command and add the _string output_ to the respective configuration values.
134
135 $ cat localhost-<key|cert>.pem | perl -pe 's/\n/\\n/g'
136
137## Common questions
138
139> What was your motivation for creating this package?
140
141I wanted a package that was lightweight and provided all of the Production features needed to create a scalable API server. While there are many packages available, most are lacking or require you to sacrifice simplicity or features for little gain.
142
143This package provides _everything_ you need to quickly build your application using a consistent and secure set of standards.
144
145> Why use Babel, and not TypeScript?
146
147If you are using [ESDoc types](https://esdoc.org/manual/tags.html) and an IDE/Editor that supports Intellisense (code completion and typing). Complexity like this is not necessary.
148
149> How do you set-up this package to use a custom database?
150
151You can update the [database wrapper](https://github.com/nuxy/nodejs-restful-jsonapi-seed/blob/master/src/lib/Database.js) example to use any [DBMS](https://www.npmjs.com/search?q=dbms) package available while extending the application [SessionStore](https://github.com/nuxy/nodejs-restful-jsonapi-seed/blob/master/src/lib/SessionStore.js) to use a compatible [Connection Session Store](https://github.com/expressjs/session#compatible-session-stores) module.
152
153## Windows support
154
155This package has limited support for Windows due to cross-platform compatibility issues, most notably `SHELL` environment differences. Due to this, you can either run this package in [Docker](https://docker.com) or switch to a UNIX-like operating system.
156
157## Contributions
158
159If you fix a bug, or have a code you want to contribute, please send a pull-request with your changes. (Note: Before committing your code please ensure that you are following the [Node.js style guide](https://github.com/felixge/node-style-guide))
160
161## Versioning
162
163This package is maintained under the [Semantic Versioning](https://semver.org) guidelines.
164
165## License and Warranty
166
167This package is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose.
168
169_nodejs-restful-jsonapi-seed_ is provided under the terms of the [MIT license](http://www.opensource.org/licenses/mit-license.php)
170
171## Author
172
173[Marc S. Brooks](https://github.com/nuxy)