Vercel Express API boilerplate
Opinionated Node.js template for creating simple APIs and PoCs using Express1 on Vercel's serverless platform.
Motivation
Simply put, I got tired of having to do the same dance EVERY SINGLE TIME I needed to quickly spin up an API for a POC I'm working on, or small (micro? π) services I spin up.
Usage
Making use of this template is pretty straightforward. Three ways...
- Clone it,
- Fork it, or,
- Even better, generate a new project on Github using this as a template.
Project Structure
.
βββ app.js
βββ config/
βββ controllers/
βββ node_modules/
βββ package.json
βββ routes/
β βββ demo.route.js
β βββ index.js
βββ services/
βββ common/
βββ vercel.json
βββ yarn.lock
Brief Overview
app.js
Express app entry point
config/
for configuration stuff... for example, database connection setup
controllers/
mostly express route handlers
node_modules/
black hole π
routes/
index.js
β bootstraps all routes. new namespaces should always be registered heredemo.route.js
β sample standalone route
services/
for "external" services (e.g. a weather.service.js file for interacting with darksky API)
common/
Β―\_(γ)_/Β―
Bundled Endpoints
After cloning/forking this template, the following endpoints can be immediately accessed:
GET /
GET /demo
1 depending on your use-case, making use of Express with Vercel's serverless platform may not be ideal as they suggest making use of the helpers provided for handling requests and making use of the Vercel config file for routing.
While I do make use of the helpers and routing for some projects (sample), I also love using Express as it drastically reduces routing complexity, I've not had any issues with setup, AND, it makes whatever project developed platform agnostic.