How to structure a serverless REST API with Firebase Functions + Express

Creating a simple script with Functions is easy. Once you go beyond trivial, intelligent file structure will really matter.

"hosting": {
"public": "public",
"rewrites": [
{
"source": "/api/**",
"function": "api"
}
],

"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
]
}
{
"compilerOptions": {
"module": "commonjs",
"noImplicitReturns": true,
"noUnusedLocals": true,
"outDir": "dist",
"sourceMap": true,
"strict": true,
"target": "es2017"
},
"compileOnSave": true,
"include": [
"src"
]
}
app.get('/articles', (req: Request, res: Response) => {
get_articles(req, res, db);
return;
});
import { requireAuth } from ‘./helpers/auth’;
app.get('/articles', requireAuth, (req: Request, res: Response) => {
get_articles(req, res, db);
return;
});

CTO @ Echelon Fitness. Founder of MileSplit. Entrepreneur, technology executive, historian, writer, Christian, family man, and track & field fan.