Ep.04: How to scaffold a project (Settings & Configuration)
This article is part of an in-depth comparison series of the top Node frameworks. We'll cover all the important aspects: market share, learning curve, ecosystem, security and more. To compare them properly, we will build the exact same app in all these frameworks (plus Vanilla Node), observe all the steps along the way and then benchmark them as we progressively add more functionalities.
Table of contents
We're almost ready to start building an app. Now, before we go all keyboard-happy and start building, we want to avoid repeating the configuration files every time we try a new framework. We need a template with settings and configurations first. These should address a few other aspects that don't qualify as Cross-Cutting Concerns but are very important.
If you ever opened a node app you probably saw the root directory is littered with lots of weird scary colorful files - these are them configurations we want, things like linting, formatting, credentials, configs, and so on.
You don't need to go through all these, you can just take my word for it and hope none of these files contains a script that will lock the door to your bathroom at random inconvenient times or switch your TV to a soap opera during your favorite Muppets show. If you are curious, do read through and/or have a look at the template repo I'll use as a starting point.
Versioning
Code Formatting
Linting
领英推荐
Git config
NPM config
It just has a bunch of generic or even empty scripts to start, test, format and build the app.
IDE config
Credentials / Configuration management
TypeScript configuration
{
"compilerOptions": {
// For "module" (module resolution), you might be tempted to use "ES2015" or more recent instead of "commonjs", but that's not the right choice for Node backend (it's more appropriate for a browser environment).
"module": "commonjs",
// You should stick to a more backwards compatible "target" in a production environment. However, since we're here to experiment, we'll use the latest ECMA Script specification
"target": "esnext",
// Allow default imports from modules with no default export
"allowSyntheticDefaultImports": true,
// Allow importing JSON files directly as modules in TypeScript
"resolveJsonModule": true,
// Generate corresponding .d.ts declaration files
"declaration": true,
// Generate source map files for debugging TypeScript code
"sourceMap": true,
// Enable the generation of decorator metadata in emitted JavaScript output and support for experimental TypeScript decorator syntax. Some frameworks like Nest will need it
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
// Specify the output directory for compiled JavaScript files
"outDir": "./dist",
// Set the base directory for resolving non-relative module names
"baseUrl": "./",
// Enable incremental compilation, speeding up the compilation process
"incremental": true,
// Skip type checking of declaration files from external libraries
"skipLibCheck": true,
// Remove all comments from the compiled JavaScript files
"removeComments": true,
// Enable strict null checks, catching common null-related errors
"strictNullChecks": true,
// Disallow the use of implicit any types, enforcing type safety
"noImplicitAny": true,
// Enable strict checks for bind, call, and apply methods on functions
"strictBindCallApply": true,
// Force consistency in file names, preventing case sensitivity issues
"forceConsistentCasingInFileNames": true,
// Enforce a check for missing break statements in switch statements
"noFallthroughCasesInSwitch": true
}
// Although tempting, avoid "esModuleInterop": true, it creates more problems than it solves. Use with caution.
}
CI/CD configuration
NPM config
# Set the default registry
registry=https://your-npm-registry.org/
# Avoid running npm audit automatically on install
audit=false
# Set the proxy if needed
proxy=https://your-proxy-url/
https-proxy=https://your-proxy-url/
# Enable npm's offline mode
offline=true
# Define custom scripts shell
script-shell=/bin/bash
# Specify the cache directory
cache=/path/to/npm-cache
# Set Node.js version
node-version=20
engine-strict=true
Containerization