Overview
The Sistema de Permisos Municipales requires configuration for database connections, server settings, sessions, and file storage. This guide covers all configurable aspects of the system.Database configuration
Connection settings
Database connection is configured insrc/keys.js and src/database.js.
src/keys.js:
Environment variables
Recommended production configuration using environment variables:Example .env file
Example .env file
Server configuration
Server settings are defined insrc/index.js.
Port configuration
The server runs on port 4000 by default. Change this via the PORT environment variable.
View engine
Static files
src/public/:
- CSS:
src/public/CSS/ - JavaScript:
src/public/JS/ - Bootstrap:
src/public/bootstrap/ - Server files:
src/public/server-files/
Session configuration
Sessions are configured with express-session:Session cookie name. Default:
permisos_municipales_passSession encryption secret. Change this in production!
Force session save on every request. Set to
false for better performance.Save new but unmodified sessions. Set to
false to comply with GDPR.Production session configuration
File upload configuration
File uploads are handled by Multer with specific storage configurations.Temporary storage
Files are initially uploaded to a temporary directory:Final storage locations
After validation, files are moved to permanent locations:Bebidas
src/public/server-files/asuntos_publicos/permisos_municipales/bebidas/Publicidad
src/public/server-files/asuntos_publicos/permisos_municipales/publicidad/Eventos
src/public/server-files/asuntos_publicos/permisos_municipales/eventos/File naming convention
Uploaded files are renamed with timestamps:Ensure these directories exist and have write permissions before starting the server.
Socket.io configuration
WebSocket server is initialized after the HTTP server:Socket.io v4.4.1 is used for real-time updates. See the WebSockets documentation for details.
Middleware configuration
The application uses several Express middlewares:Route configuration
Routes are modularized and mounted at specific paths:Initial setup
The system creates an initial admin user on startup:- Username:
ADMINS - Password:
ADMIN(hashed with bcrypt) - Role:
Administrador
Production deployment
For production environments, consider these configurations:Using PM2
pm2 start ecosystem.config.js
Nginx reverse proxy
SSL/HTTPS configuration
Configuration checklist
Database setup
- Create
asuntos_publicosdatabase - Run
database/database.sqlschema - Configure database credentials in
src/keys.js - Test database connection
Environment variables
- Set
DB_HOST,DB_USER,DB_PASSWORD,DB_NAME - Set
PORT(default 4000) - Set
SESSION_SECRET(generate random string) - Set
NODE_ENV=productionfor production
File storage
- Create directory structure:
src/public/server-files/temps/src/public/server-files/asuntos_publicos/permisos_municipales/bebidas/src/public/server-files/asuntos_publicos/permisos_municipales/publicidad/src/public/server-files/asuntos_publicos/permisos_municipales/eventos/
- Set appropriate write permissions
Server configuration
- Install all dependencies:
npm install - Configure PM2 for production
- Set up Nginx reverse proxy
- Configure SSL certificates
- Set up firewall rules (allow port 80/443, block 4000)
Troubleshooting
Server won't start
Server won't start
Possible causes:
- Port 4000 already in use
- Database connection failed
- Missing dependencies
- Check if another process is using port 4000:
lsof -i :4000 - Verify database is running and credentials are correct
- Run
npm installto install dependencies
Session not persisting
Session not persisting
Possible causes:
- Session secret not configured
- Cookie settings incompatible with environment
- Set
SESSION_SECRETenvironment variable - For HTTPS, ensure
cookie.secureis true - Check browser cookie settings
File uploads failing
File uploads failing
Possible causes:
- Directories don’t exist
- Insufficient permissions
- Disk space full
- Create required directories
- Set proper permissions:
chmod 755on upload directories - Check disk space:
df -h
Next steps
Installation guide
Complete installation instructions
Security
Security best practices and hardening