Registry / database / mysql-restapi

mysql-restapi

JSON →
library1.2.6jsnpmunverified

mysql-restapi is a Node.js module (v1.2.6, last updated in 2020) that bridges MySQL databases and REST APIs using Express. It auto-generates CRUD endpoints for any table, supports custom SQL queries, CORS configuration, and optional login field validation. Unlike ORM-based solutions, it requires manual Express and mysql setup but offers simple API URL customization with limit, order, and field filtering query parameters. Maintenance is low, with minimal updates and no active development.

npm install mysql-restapi
INSTALL
IMPORT
SIG · MYSQL-RESTAPI
M
mysql-restapi
databasejavascriptv1.2.6
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.

mysql-restapi
const mysqlrestapi = require('mysql-restapi');
import mysqlrestapi from 'mysql-restapi';
The package uses CommonJS and does not support ESM imports.
default
const mysqlrestapi = require('mysql-restapi');
const { default: mysqlrestapi } = require('mysql-restapi');
No default export object; the required value is directly callable.
require
const mysqlrestapi = require('mysql-restapi');
const restapi = require('mysql-restapi').default;
The module exports a single function, not an object with properties.

Sets up a basic Express server with mysql-restapi, exposing CRUD APIs for any MySQL table.

const express = require('express'); const mysql = require('mysql'); const mysqlrestapi = require('mysql-restapi'); const dbconfig = require('./connections'); // see connections.js in README const app = express(); const api = mysqlrestapi(app, dbconfig); app.listen(3000, () => console.log('Server running on port 3000')); // connections.js content: // const mysql = require('mysql'); // const connection = mysql.createPool({ // host: process.env.DB_HOST ?? 'localhost', // user: process.env.DB_USER ?? 'root', // password: process.env.DB_PASS ?? '', // database: process.env.DB_NAME ?? 'test' // }); // const settingOptions = { apiURL: 'api', paramPrefix: '_' }; // const corsOptions = { origin: '*', methods: 'GET,POST,PUT,DELETE', allowedHeaders: 'Content-Type', credentials: true }; // module.exports = { connection, settingOptions, corsOptions };
Debug
Known issues
breakingRequires both express and mysql as peer dependencies; they are not automatically installed. Running npm install mysql-restapi without those will cause runtime errors.
fix
Run npm install express mysql --save before or alongside mysql-restapi.
affects: >=1.0.0
breakingThe module must be initialized by passing the Express app and db config as arguments; calling mysqlrestapi without arguments returns undefined and will break.
fix
Ensure you call mysqlrestapi(app, dbconfig) correctly.
affects: >=1.0.0
deprecatedThe mysql package (not mysql2) is required; using mysql2 will cause incompatibility due to different promise-based API.
fix
Install mysql (version 2.x) specifically: npm install mysql --save
affects: *
gotchaThe module exposes CRUD endpoints directly; it does not provide authentication or input sanitization beyond basic login field check. Ensure you add middleware for security.
fix
Use additional middleware like helmet and express-validator for production.
affects: *
Errors
Common errors & fixes
TypeError: mysqlrestapi is not a function
The package was not required correctly or is not installed.
fix
Verify installation: const mysqlrestapi = require('mysql-restapi'); and that the package is in node_modules.
Cannot find module 'mysql'
The mysql peer dependency is missing.
fix
Run: npm install mysql --save
Error: Cannot find module './connections'
The dbconfig file (connections.js) is not in the expected location or not exported correctly.
fix
Create connections.js in the same directory as your main file, exporting an object with connection, settingOptions, corsOptions.
Upgrade
Version history
1.2.6latest on npm
Audit
Dependencies
expressrequiredRequired as the web framework to mount the REST API endpoints.
mysqlrequiredRequired for MySQL database connection pooling and queries.
Agent activity
9 hits · last 30 days
node
8
Resources
mysql-restapi — npm install mysql-restapi · libregistry