enjinerd / tugas-web-service

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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...

  1. Clone it,
  2. Fork it, or,
  3. 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 here
  • demo.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.

About


Languages

Language:JavaScript 100.0%