A Node.js Express application demonstrating security best practices including authentication, authorization, input validation, and secure configuration, using Supabase as the backend.
- Express framework
- Supabase for database and backend services
- JWT-based Authentication
- Password Hashing with bcrypt (if implementing custom auth)
- Input Validation with express-validator
- Security Headers with Helmet
- CORS configuration
- Environment variable management with dotenv
- Logging with Winston
- Node.js (v18+ recommended)
- npm or yarn
- A Supabase project (get URL and Anon Key from your Supabase project settings)
-
Clone the repository:
git clone <repository-url> cd security-api
-
Install dependencies:
npm install # or yarn install -
Set up environment variables:
- Copy the
.env.examplefile to.env:cp .env.example .env
- Update the variables in the
.envfile:SUPABASE_URL: Your Supabase project URL.SUPABASE_ANON_KEY: Your Supabase project Anon key.JWT_SECRET: A strong, random secret for signing JWTs (generate one, don't use the example value).PORT: The port the server should listen on (default is 3000).NODE_ENV: Set todevelopmentorproduction.LOG_LEVEL: Logging level (e.g.,info,debug).JWT_EXPIRES_IN: Token expiration time (e.g.,1h,7d).
- Copy the
-
Start the server:
npm start
-
Start in development mode (with hot-reloading using nodemon):
npm run dev
/src
/api
/v1
/routes # API routes (e.g., auth.routes.js, user.routes.js)
/controllers # Request handlers
/services # Business logic (interacts with Supabase)
/middlewares # Custom middleware (e.g., authentication, validation)
/config # Configuration files (e.g., environment loader)
/models # Placeholder for potential data access layer functions (using Supabase client)
/utils # Utility functions (e.g., logger, response handlers)
/db # Supabase client initialization
app.js # Express application setup (middleware, routes)
server.js # Server initialization (HTTP server start)
.env # Environment variables (ignored by git)
.env.example # Example environment variables
.gitignore # Git ignore configuration
package.json # Project dependencies and scripts
README.md # Project documentation
(Add details about your API endpoints here once defined)
(Add contribution guidelines if applicable)
(Specify project license, e.g., ISC, MIT)