Registry / devops / node-migration

node-migration

JSON →
library1.0.1jsnpmunverified

A generic promise-based migration tool for Node.js. Version 1.0.1 is current but appears unmaintained since 2016. It tracks migration state in a JSON file and executes user-defined `up` and `down` functions in migration files. Unlike database-specific tools (e.g., sequelize, knex), node-migration is agnostic — you provide the logic. Supports synchronous and asynchronous (promise-returning) migrations. CLI: `migrate up` / `migrate down` / `migrate create`. Programmatic API via `require('node-migration').run()`. No built-in database integration; you manage connections via `setup.js`. Last release over 8 years ago; consider alternatives for production use.

npm install node-migration
INSTALL
IMPORT
SIG · NODE-MIGRATION
N
node-migration
devopsjavascriptv1.0.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

migrate
const migrate = require('node-migration')
import migrate from 'node-migration'
CJS only; no ESM exports. The package exports a single object with a `run` method.
run
migrate.run('up', { dir: './migrations', file: 'migrations.json' })
migrate.run('up', './migrations')
Second argument must be an options object with `dir` and `file` properties.
up / down
exports.up = (ctx) => { /* sync or promise */ }
module.exports = { up: (ctx) => { ... } }
Both `up` and `down` must be individual named exports; a default export object is ignored.

Installs globally, creates a migration file and setup.js, runs up and down migrations.

npm install -g node-migration mkdir migrations cd migrations cat > 1478281876745_create_users.js << 'EOF' // Replace with your DB logic const db = { createTable: () => console.log('Table created'), dropTable: () => console.log('Table dropped') } exports.up = (ctx) => { db.createTable('users') } exports.down = (ctx) => { db.dropTable('users') } EOF cat > setup.js << 'EOF' module.exports = (ctx) => { ctx.db = { query: () => {} } } EOF cd .. migrate up migrate down
Debug
Known issues
gotchaMigrations run in arbitrary order based on file timestamp (filename prefix); sort is not guaranteed on all filesystems.
fix
Prepend timestamps (e.g., Unix epoch) to filenames to ensure chronological order.
affects: *
gotchaState is stored in a JSON file by default; it can be overwritten or lost if multiple processes run concurrently.
fix
Override `getJSON` and `saveJSON` in setup.js to use a database or locking.
affects: *
deprecatedPackage unmaintained since 2016; no support for modern Node.js versions or ESM.
fix
Use actively maintained tools like `umzug`, `node-pg-migrate`, or `db-migrate`.
affects: *
Errors
Common errors & fixes
TypeError: migrate.run is not a function
Importing using ESM syntax or wrong require path.
fix
Use `const migrate = require('node-migration')` (CJS).
ENOENT: no such file or directory, open 'migrations.json'
No `file` option specified and default file missing.
fix
Provide `file` in options or create the file manually: `migrate up --file myState.json`.
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
node-migration — npm install node-migration · libregistry