hyperdata-wstore
v0.2.0
Published
WebStore server and client
Downloads
2
Readme
hyperdata-wstore
A cheap & cheerful Node.js HTTP server and minimal companion clients for file storage and retrieval.
Supports HTTP GET, POST, PUT, DELETE (RFC 9112) with HTTP Basic (RFC 7617) authentication. Includes example nginx config for proxying (you will want the server to do HTTPS for bare minimum acceptable security).
Use from source
To use the repository directly:
- Clone the repository:
git clone https://github.com/danja/wstore.git- Install dependencies:
cd wstore
npm install- Create a
.envfile in the project root with configuration:
PORT=4500
STORAGE_DIR=./storage
AUTH_USERNAME=admin
AUTH_PASSWORD=password- Start the server:
node server/WebStore.jsThe repository includes additional features and examples that may not be available in the npm package.
Graceful Server Shutdown
The server supports a secure shutdown endpoint for controlled termination. To shut down the server gracefully:
- Send a POST request to
/shutdownwith HTTP Basic authentication. - The request body must be the exact string
STOP WEBSTORE(plain text). - Example (Node.js):
import http from 'http';
const options = {
hostname: 'localhost',
port: 4500,
path: '/shutdown',
method: 'POST',
headers: {
'Authorization': 'Basic ' + Buffer.from('admin:password').toString('base64'),
'Content-Type': 'text/plain',
'Content-Length': Buffer.byteLength('STOP WEBSTORE')
}
};
const req = http.request(options, res => {
res.on('data', chunk => process.stdout.write(chunk));
});
req.write('STOP WEBSTORE');
req.end();If the credentials and shutdown command are correct, the server will respond and then terminate after a short delay.
Use as a library
Install the package using npm:
npm install hyperdata-wstore- Create a
.envfile in your project root with configuration:
PORT=4500
STORAGE_DIR=./storage
AUTH_USERNAME=admin
AUTH_PASSWORD=password- Create a server file (e.g.,
server.js):
import WebStore from 'hyperdata-wstore'
// Optionally override configuration
// process.env.PORT = '4500'
// process.env.STORAGE_DIR = './storage'
// process.env.AUTH_USERNAME = 'admin'
// process.env.AUTH_PASSWORD = 'password'
// Start the server
const server = WebStore.listen(config.port, config.host, () => {
console.log(`WebStore server running at http://${config.host}:${config.port}`)
console.log(`Storage directory: ${config.storageDir}`)
console.log(`Authentication: ${config.auth.username}/${config.auth.password}`)
})
export { server }- Run your server:
node server.jsConfiguration
The WebStore server can be configured using environment variables. The package will automatically load a .env file from your project root directory.
Available configuration options:
# Server configuration
PORT=4500 # Port to listen on
HOST=localhost # Host to bind to
# Storage directory (relative to project root)
STORAGE_DIR=storage
# Authentication credentials
AUTH_USERNAME=admin
AUTH_PASSWORD=password
# Logging configuration
LOG_LEVEL=info # loglevel severity: trace, debug, info, warn, error, silent
# Optional: Database configuration
DB_HOST=localhost
DB_PORT=5432
DB_NAME=webstore
DB_USER=webstore
DB_PASSWORD=webstoreCLI Usage
The package also provides a command-line interface:
# Start the server
hyperdata-wstore
# Start with custom configuration
PORT=4500 hyperdata-wstoreQuick Setup
Install:
npm install hyperdata-wstoreStart server:
npm startStore files:
curl -u admin:password -X POST -H "Content-Type: application/json" \ -d '{"hello": "world"}' http://localhost:4500/hello.jsonRetrieve files:
curl http://localhost:4500/hello.json
Configuration
Set these environment variables:
STORAGE_DIR: Directory to store files (defaults to./storage)PORT: Port number to listen on (defaults to 4500)AUTH_USERNAME: Username for write operationsAUTH_PASSWORD: Password for write operations
Security
- Always run behind HTTPS
- Use strong credentials
- Consider rate limiting
- Monitor access logs
Supported Operations
GET: Retrieve files or list directoriesPOST: Create new files (fails if exists)PUT: Create or update filesDELETE: Remove files
Production Setup
- Use a reverse proxy (e.g., nginx) for HTTPS
- Set up proper logging
- Configure timeouts
- Add caching headers
There are more detailed notes in README-long.md.
Troubleshooting
pkill -f "node server/WebStore.js" || true && node server/WebStore.js
