Registry / database / natis
library3.0.1jsnpmunverified

Natis is a MySQL utility library (version 3.0.1) that provides a thin wrapper around the mysql2 package for Node.js. It simplifies common MySQL operations such as querying, connection pooling, and transaction management with a promise-based API. Unlike full-fledged ORMs like Sequelize or TypeORM, Natis focuses on lightweight, minimal abstraction, giving developers direct SQL control while handling connection lifecycle and error retries. It is released on an as-needed cadence, with v3 introducing breaking changes to the API (async/await required, no callback support). Requires mysql2 as a peer dependency and supports TypeScript definitions.

npm install natis
INSTALL
IMPORT
SIG · NATIS
N
natis
databasejavascriptv3.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.

createConnection
import { createConnection } from 'natis'
const { createConnection } = require('natis')
ESM-only since v3. For older versions, use require with .default.
NatisClient
import { NatisClient } from 'natis'
import NatisClient from 'natis'
NatisClient is a named export, not default.
query
import { query } from 'natis'
import { query } from 'natis/query'
All exports are at the package root, no subpath exports.

Establishes a MySQL connection using createConnection, creates a table, inserts a row, and queries all rows.

import { createConnection, query } from 'natis'; async function main() { const conn = await createConnection({ host: 'localhost', user: 'root', password: process.env.DB_PASSWORD ?? '', database: 'test' }); await query(conn, 'CREATE TABLE IF NOT EXISTS users (id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255))'); const result = await query(conn, 'INSERT INTO users (name) VALUES (?)', ['Alice']); console.log('Insert ID:', result.insertId); const rows = await query(conn, 'SELECT * FROM users'); console.log('Users:', rows); await conn.end(); } main().catch(console.error);
Debug
Known issues
breakingNatis v3 is ESM-only. Requires Node.js >= 14 and 'type': 'module' in package.json.
fix
Switch to ESM imports (import { ... } from 'natis') or continue using v2.x for CommonJS support.
affects: >=3.0.0
breakingAll API methods return Promises; callbacks removed in v3.
fix
Use async/await or .then() instead of callback functions.
affects: >=3.0.0
deprecatedThe 'pool' export is deprecated since v2.5 in favor of createPool.
fix
Replace 'pool' with 'createPool' from '@natis/core' or upgrade to v3.
affects: >=2.5.0 <3.0.0
gotchaConnection objects are not directly reusable after a query error; you must create a new connection.
fix
Always check connection state and re-create on error. Use connection pools for reliability.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'natis' or its corresponding type declarations.
Missing peer dependency mysql2 or installed in wrong environment.
fix
npm install natis mysql2
Error: Must use import to load ES Module: /path/to/node_modules/natis/index.js
Using CommonJS require() with v3 ESM-only package.
fix
Use dynamic import: const natis = await import('natis') or add 'type': 'module' to package.json.
TypeError: conn.query is not a function
Misunderstanding API: query is a standalone function, not a method on connection.
fix
Use query(conn, 'SQL') instead of conn.query().
Upgrade
Version history
3.0.1latest on npm
Audit
Dependencies
mysql2requiredNatis wraps mysql2 for MySQL protocol handling and connection pooling.
Agent activity
12 hits · last 30 days
node
12
Resources
packagenatis
natis — npm install natis · libregistry