generator-express-no-stress
Create awesome Express.js applications with best of breed tech including ES.next via Babel.js, structured logging with Pino, API validation and interactive documentation via Swagger, environment based config with dotenv, and linting with ESLint.
generator-express-no-stress gets you up and running in seconds. It's ridiculously easy to configure. Heck, just take the defaults. Start it. Write code.
This generator scaffolds a fully functioning REST API server, complete with interactive documentation, API validation, structured logging, environment driven config, and more. Simply run the generator and smile :-D
Install
Requires Node 8 or greater
npm install -g yo generator-express-no-stress
Scaffold
yo express-no-stress myapp
cd myapp
Run
Run in development mode:
npm run dev
Package and run in production mode
npm run compile
npm start
Test
npm test
Debug
Run one of the following, then attach your favorite inspector e.g. VSCode:
# debug the server
npm run dev:debug
# debug the tests
npm run test:debug
Try it!
- Interactive API doc at http://localhost:3000/api-explorer
- Landing page at http://localhost:3000
Usage: CLI
yo express-no-stress [appname] [--yarn] [--docker]
Option | default | Description |
---|---|---|
appname |
myapp | The application folder |
--yarn |
- | Use the yarn package manager, instead of npm |
--docker |
Install Docker artifacts including a Dockerfile |
Usage: Project
The sections below describe all usage options available once the project is generated/scaffolded.
npm targets
Target | Description |
---|---|
npm run dev |
Run in development mode |
npm run dev:debug |
Debug in development mode |
npm run test |
Run tests |
npm run test:debug |
Deubg tests |
npm run lint |
View a listing of all errors discovered by the linter |
npm run lint:fix |
Fix all errors discovered by the linter |
npm run compile |
Transpile source code for production use |
npm start |
Run the in production mode. *Requires running npm run compile first |
Debug in VSCode
Add these contents to your .vscode/launch.json
file
Deploy to the Cloud
e.g. CloudFoundry
cf push myapp
Use Yarn
# scaffold
yo express-no-stress myapp --yarn
# start
cd myapp
npm start
What you get!
-
Express.js - Fast, unopinionated , minimalist web framework for Node.js
-
Babel.js - Use new syntax, right now without waiting for support
-
Pino - Extremely fast node.js logger, inspired by Bunyan. It also includes a shell utility to pretty-print its log files
-
dotenv - Loads environment variables from .env for nodejs projects
-
ESLint - a pluggable linting utility for JavaScript and JSX
Choose from the following ESLint lint rules:
-
Swagger - is a simple yet powerful representation of your RESTful API
-
SwaggerUI - dynamically generate beautiful documentation and sandbox from a Swagger-compliant API
API Validation
Simply describe your APIs with Swagger and automagically get for free:
- Interactive documentation
- API validation
Interactive API Doc
API Validation!
Oops! I the API caller forgot to pass a name
field, no stress, we've got this!
Structured Logging
Structured logging out of the box!
raw
pretty
Structured logging pretty printed by default - great for dev!
API Validation Example
Simply describe your APIs with Swagger and automatically get:
- API request validation
- Interactive documentation
example
Swagger API spec
swagger: '2.0'
info:
version: 1.0.0
title: myapp
description: My cool app
basePath: /api/v1
tags:
- name: Examples
description: Simple example endpoints
- name: Specification
description: The swagger API specification
consumes:
- application/json
produces:
- application/json
definitions:
ExampleBody:
type: object
title: example
required:
- name
properties:
name:
type: string
example: no_stress
paths:
/examples:
get:
tags:
- Examples
description: Fetch all examples
responses:
200:
description: Returns all examples
post:
tags:
- Examples
description: Create a new example
parameters:
- name: example
in: body
description: an example
required: true
schema:
$ref: "#/definitions/ExampleBody"
responses:
200:
description: Returns all examples
/examples/{id}:
get:
tags:
- Examples
parameters:
- name: id
in: path
required: true
description: The id of the example to retrieve
type: integer
responses:
200:
description: Return the example with the specified id
404:
description: Example not found
/spec:
get:
tags:
- Specification
responses:
200:
description: Return the API specification
Invoke a POST request via the Interactive doc
Linting
express-no-stress uses ESLint and provides two choices, Airbnb or Prettier.
To add your own ESLint customizations, edit.eslintrc.json
.
Note that the Airbnb variant provides a slightly modified Airbnb base configuration.
FAQs
Q: What about Node.js 6.x?
A:generator-express-no-stress
now uses Babel 7. Babel 7 tooling requires Node.js 8 or greater. To use generator-express-no-stress
with Node.js 6, install version 3.5.4.
npm install -g yo generator-express-no-stress@3.5.4