Registry / database / diet-mysql

diet-mysql

JSON →
library2.0.0jsnpmunverified

A plugin for the Diet.js web framework that provides a simplified wrapper around the popular node-mysql module. Version 2.0.0 requires Node >=5.7.0 and works with Diet.js to manage MySQL connections per request. It automatically opens a connection on each route and closes it when the response is sent. The main differentiation is tight integration with Diet.js's signal system, exposing $.mysql.query inside routes. It relies on the 'mysql' npm package and has minimal overhead (20kb). Note that this package is specific to the Diet.js framework and is not actively maintained (last update years ago).

npm install diet-mysql
INSTALL
IMPORT
SIG · DIET-MYSQL
D
diet-mysql
databasejavascriptv2.0.0
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.

diet-mysql
const mysql = require('diet-mysql')
import mysql from 'diet-mysql'
This package is CommonJS-only; ESM import will fail.
mysql.connect
mysql.connect({ app: app, database: 'db' })
mysql({ app: app, database: 'db' })
connect is a method, not the default export callable directly.
$.mysql.query
$.mysql.query('SQL', callback)
$.mysql.query('SQL').then(callback)
Returns a callback-based API; no Promise support natively.

Sets up a Diet.js app, connects to MySQL, and defines a route that queries 'accounts' and returns JSON.

const server = require('diet'); const app = server().listen(6500); const mysql = require('diet-mysql'); mysql.connect({ app: app, database: 'your_project', host: 'localhost', user: 'root', password: process.env.MYSQL_PASSWORD || '' }); app.get('/', function($){ $.mysql.query('SELECT * FROM accounts', function(error, accounts){ if(error) throw error; $.data.accounts = accounts; $.json(); }); });
Debug
Known issues
gotchaDepends on outdated 'mysql' package (not 'mysql2'), lacking modern features like prepared statements and async/await.
fix
Consider using mysql2 directly or a more modern ORM.
affects: >=2.0.0
gotchaConnection management: each request opens a new connection; automatic close on $.end() may lead to resource exhaustion under high load.
fix
Implement connection pooling manually or switch to a pool-based solution.
affects: all
gotchaThe plugin does not validate options; missing 'app' or 'database' crashes silently.
fix
Always include 'app' and 'database' in connect options.
affects: all
deprecatedNo updates since 2016; known vulnerabilities in dependent 'mysql' package may apply.
fix
Audit or migrate to actively maintained alternatives like 'mysql2' with a custom Diet middleware.
affects: all
Errors
Common errors & fixes
Error: Cannot find module 'diet'
The 'diet' package is not installed or not in node_modules.
fix
Install diet: npm install diet
TypeError: mysql.connect is not a function
Using 'mysql' as a function call instead of importing the module then calling .connect.
fix
const mysql = require('diet-mysql'); mysql.connect({...});
Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'root'@'localhost'
Invalid MySQL credentials or no password provided.
fix
Check your MySQL user/password and pass them in connect options.
Upgrade
Version history
2.0.0latest on npm
Audit
Dependencies
mysqlrequiredCore MySQL driver for Node.js
dietoptionalPeer dependency – Diet.js web framework
Agent activity
7 hits · last 30 days
node
6
Resources
diet-mysql — npm install diet-mysql · libregistry