express-no-stress: Build awesome APIs with Express.js and Swagger
In this brief article, I'll show you how to scaffold an API application using Node.js along with best-of-breed technologies and approaches. I will introduce the express-no-stress generator, which can be used to quickly scaffold a new API application that's built on Express.js. This scaffolding provides structured logging, API request validation, interactive API documentation, environment-driven configuration, a simple build/transpilation process, and more. The scaffolded application is also suitable for deployment on modern cloud platforms like IBM Cloud.
Why is this important? Nowadays, software is often delivered as a service on the web, and this is the software that drives the API economy. APIs create value by delivering on what others want: They help developers innovate freely, drive change, connect seemingly disparate domains, and ultimately deliver new value.
When building APIs, it is important to meet the needs of the developers who consume them. APIs must be dependable, scalable, intuitive, and easy to use. They must also minimize the time and cost required to maintain them. Ideally, an API application is also:
- easy to set up and automate
- easy to port between execution environments
- suitable for deployment to the cloud
- and requires minimal effort with respect to systems administration and monitoring
Fortunately, the express-no-stress generator creates applications that meet these demands. express-no-stress is a mini-project that I started—a Yeoman generator that scaffolds a consistent, fully functional REST API. express-no-stress combines the tools you need to build awesome apps. It takes just seconds to generate, and allows you to focus on what’s important—writing application code.
- Express.js—a fast, unopinionated , minimalist web framework for Node.js.
- Bunyan—a simple and fast (JSON) structured logging module for Node.js.
- dotenv—loads environment variables from .env. (12factor tenant III).
- Backpack—a minimalistic build system for Node.js.
- Swagger—a simple yet powerful representation of your RESTful API.
- SwaggerUI—dynamically generated, beautiful documentation and sandbox from a Swagger-compliant API.
- Cloud Ready—deploy to any cloud; a CloudFoundry/IBM Cloud example is provided (see README).
To see the out-of-the-box scaffolded app in action, visit https://express-no-stress-scaffolded-app.mybluemix.net.
Note: The scaffolding provides only a minimal example API, so it's up to you to implement your API code the way you want.
To get started with express-no-stress, go to the GitHub repo.
For the impatient, you can run:
npm install -g yo generator-express-no-stress yo express-no-stress myapp
The express-no-stress Yeoman generator makes is easy to quickly create web APIs with Node.js and Express. It’s a useful tool to have in your toolbox—great for both production and side projects. If you're working in a microservices environment (or even if you're not), express-no-stress helps to ensure that new Node.js APIs are scaffolded consistently and use a common set of solid tools. Check it out!