Nomine: Express Middleware for File Renaming

raw JSON →
4.0.0 verified Thu Apr 23 auth: no javascript

Nomine is an Express.js middleware package that facilitates renaming files and folders through HTTP PUT requests. It provides a straightforward API to expose a file renaming endpoint within an Express application, which is typically used for administrative interfaces or content management systems that require remote file system manipulation. The current stable version is 4.0.0, which mandates Node.js version 10 or higher, continuing a pattern of dropping support for older Node.js versions in each major release. The package's release cadence is driven primarily by updates to its internal dependencies and adjustments to Node.js compatibility. Its main differentiator is its direct integration into the Express ecosystem, offering a pre-packaged solution for network-based file renaming operations, abstracting the underlying file system interactions by utilizing the `renamify` package for the core renaming logic.

error EACCES: permission denied, rename '/bin' -> '/bin2'
cause The Node.js process does not have sufficient permissions to perform file operations (read, write, rename) in the specified directory or on the target files.
fix
Ensure the Node.js process has appropriate file system permissions for the directories and files it attempts to modify. Avoid attempting to rename system-critical directories like /bin on production servers. Use relative paths or explicitly designated user data directories.
error Error: Router.use() requires a middleware function but got a undefined
cause The `nomine` package was not correctly imported or called as a function before being passed to `app.use()`, resulting in `undefined` instead of a middleware function.
fix
Ensure const nomine = require('nomine'); is at the top of your file and that app.use(nomine({ /* options */ })); is used, calling nomine() to get the middleware function.
breaking Nomine v4.0.0 dropped support for Node.js versions older than 10. Applications running on Node.js 8 or earlier will not function correctly.
fix Upgrade your Node.js environment to version 10 or higher before upgrading to nomine v4.0.0.
breaking Nomine v3.0.0 dropped support for Node.js versions older than 8.
fix Upgrade your Node.js environment to version 8 or higher. For Node.js versions below 8, use nomine v2.x.
breaking Nomine v2.0.0 dropped support for Node.js versions older than 4.
fix Upgrade your Node.js environment to version 4 or higher. For Node.js versions below 4, use nomine v1.x.
gotcha Exposing file system operations via HTTP, especially rename, presents significant security risks. Without robust authentication and authorization mechanisms in place, an attacker could rename critical system files.
fix Always implement strong authentication (e.g., user sessions, API keys) and fine-grained authorization checks before using `nomine` in production. Restrict the `dir` parameter to only allow operations within designated user directories or safe zones.
npm install nomine
yarn add nomine
pnpm add nomine

This quickstart initializes an Express server, integrates the `nomine` middleware, and listens on port 3000. It demonstrates how to configure a custom endpoint for rename operations and provides a `curl` example for testing.

const express = require('express');
const nomine = require('nomine');
const app = express();

// Use nomine middleware with a custom prefix
app.use(nomine({
    prefix: '/files/rename' // default is '/rename'
}));

app.listen(3000, function () {
    console.log('Nomine example app listening on port 3000!');
    console.log('Send PUT requests to http://localhost:3000/files/rename');
    console.log('Example curl: curl -X PUT -H "Content-Type: application/json" -d \'{"dir":"/tmp","from":["oldfile.txt"], "to": ["newfile.txt"]}\' http://localhost:3000/files/rename');
});