{"id":45506,"library":"mysql-restapi","title":"mysql-restapi","description":"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.","status":"maintenance","version":"1.2.6","language":"javascript","source_language":"en","source_url":"https://github.com/jitendra5984/mysql-restapi","tags":["javascript","sql","mysql","rest","api","rest api","restapi","express","expressjs"],"install":[{"cmd":"npm install mysql-restapi","lang":"bash","label":"npm"},{"cmd":"yarn add mysql-restapi","lang":"bash","label":"yarn"},{"cmd":"pnpm add mysql-restapi","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required as the web framework to mount the REST API endpoints.","package":"express","optional":false},{"reason":"Required for MySQL database connection pooling and queries.","package":"mysql","optional":false}],"imports":[{"note":"The package uses CommonJS and does not support ESM imports.","wrong":"import mysqlrestapi from 'mysql-restapi';","symbol":"mysql-restapi","correct":"const mysqlrestapi = require('mysql-restapi');"},{"note":"No default export object; the required value is directly callable.","wrong":"const { default: mysqlrestapi } = require('mysql-restapi');","symbol":"default","correct":"const mysqlrestapi = require('mysql-restapi');"},{"note":"The module exports a single function, not an object with properties.","wrong":"const restapi = require('mysql-restapi').default;","symbol":"require","correct":"const mysqlrestapi = require('mysql-restapi');"}],"quickstart":{"code":"const express = require('express');\nconst mysql = require('mysql');\nconst mysqlrestapi = require('mysql-restapi');\n\nconst dbconfig = require('./connections'); // see connections.js in README\nconst app = express();\n\nconst api = mysqlrestapi(app, dbconfig);\n\napp.listen(3000, () => console.log('Server running on port 3000'));\n\n// connections.js content:\n// const mysql = require('mysql');\n// const connection = mysql.createPool({\n//   host: process.env.DB_HOST ?? 'localhost',\n//   user: process.env.DB_USER ?? 'root',\n//   password: process.env.DB_PASS ?? '',\n//   database: process.env.DB_NAME ?? 'test'\n// });\n// const settingOptions = { apiURL: 'api', paramPrefix: '_' };\n// const corsOptions = { origin: '*', methods: 'GET,POST,PUT,DELETE', allowedHeaders: 'Content-Type', credentials: true };\n// module.exports = { connection, settingOptions, corsOptions };","lang":"javascript","description":"Sets up a basic Express server with mysql-restapi, exposing CRUD APIs for any MySQL table."},"warnings":[{"fix":"Run npm install express mysql --save before or alongside mysql-restapi.","message":"Requires both express and mysql as peer dependencies; they are not automatically installed. Running npm install mysql-restapi without those will cause runtime errors.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Ensure you call mysqlrestapi(app, dbconfig) correctly.","message":"The module must be initialized by passing the Express app and db config as arguments; calling mysqlrestapi without arguments returns undefined and will break.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Install mysql (version 2.x) specifically: npm install mysql --save","message":"The mysql package (not mysql2) is required; using mysql2 will cause incompatibility due to different promise-based API.","severity":"deprecated","affected_versions":"*"},{"fix":"Use additional middleware like helmet and express-validator for production.","message":"The module exposes CRUD endpoints directly; it does not provide authentication or input sanitization beyond basic login field check. Ensure you add middleware for security.","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"search_vec":"'2020':15 'activ':79 'api':22,60,85,87 'auto':27 'auto-gener':26 'base':48 'bridg':17 'configur':39 'cor':38 'crud':29 'custom':35,62 'databas':19 'develop':80 'endpoint':30 'express':24,53,89 'expressj':90 'field':43,67 'filter':68 'generat':28 'javascript':81 'last':12 'limit':64 'login':42 'low':73 'mainten':71 'manual':52 'minim':75 'modul':10 'mysql':2,5,18,55,83 'mysql-restapi':1,4 'node.js':9 'offer':58 'option':41 'order':65 'orm':47 'orm-bas':46 'paramet':70 'queri':37,69 'requir':51 'rest':21,84,86 'restapi':3,6,88 'setup':56 'simpl':59 'solut':49 'sql':36,82 'support':34 'tabl':33 'unlik':45 'updat':13,76 'url':61 'use':23 'v1.2.6':11 'valid':44","created_at":"2026-06-07T12:55:20.644595+00:00","updated_at":"2026-06-07T12:55:20.644595+00:00","problems":[{"fix":"Verify installation: const mysqlrestapi = require('mysql-restapi'); and that the package is in node_modules.","cause":"The package was not required correctly or is not installed.","error":"TypeError: mysqlrestapi is not a function"},{"fix":"Run: npm install mysql --save","cause":"The mysql peer dependency is missing.","error":"Cannot find module 'mysql'"},{"fix":"Create connections.js in the same directory as your main file, exporting an object with connection, settingOptions, corsOptions.","cause":"The dbconfig file (connections.js) is not in the expected location or not exported correctly.","error":"Error: Cannot find module './connections'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/jitendra5984/mysql-restapi#readme","github":"https://github.com/jitendra5984/mysql-restapi","docs":null,"changelog":null,"pypi":null,"npm":"mysql-restapi","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}