@gotocva/express-env
v1.0.0
Published
Express middleware to update .env file dynamically
Downloads
5
Readme
@gotocva/express-env
Overview
@gotocva/express-env is an Express middleware that allows secure and dynamic updates to the .env file of an Express project. It provides:
- A POST API to update environment variables.
- A GET API to retrieve all environment variables.
- Optional authentication for security.
Installation
Install the package using npm:
npm install @gotocva/express-envUsage
1. Import and Use Middleware in Express App
const express = require('express');
const expressEnv = require('@gotocva/express-env');
const app = express();
app.use(express.json());
// Initialize middleware with authentication (optional)
app.use(expressEnv({ auth: { token: 'your_secure_token' } }));
app.listen(3000, () => console.log('Server running on port 3000'));2. Update Environment Variables via API
Endpoint: POST /gotocva/env
Request Body:
{
"key": "API_KEY",
"value": "123456",
"authToken": "your_secure_token"
}Response:
{
"success": true,
"message": "Environment variable updated"
}3. Retrieve All Environment Variables
Endpoint: GET /gotocva/env?authToken=auth_token
Response:
{
"success": true,
"env": {
"API_KEY": "123456"
}
}Security Considerations
- Always enable authentication (
authToken) to prevent unauthorized changes. - Restrict access using middleware like
corsor IP whitelisting.
License
This project is licensed under the MIT License.
