Registry / database / require-sql

require-sql

JSON →
library1.0.0jsnpmunverified

This package extends Node.js require() to support .sql files, returning the file contents as a plain string. Version 1.0.0 is the only release with no active development or updates. It is a simple convenience tool that avoids JavaScript multiline string syntax, but has no notable differentiators other than its minimal API. It essentially registers an extension handler for .sql files via require.extensions.

npm install require-sql
INSTALL
IMPORT
SIG · REQUIRE-SQL
R
require-sql
databasejavascriptv1.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.

default
import 'require-sql'
const requireSql = require('require-sql');
The package is a side-effect require that registers a .sql extension handler. It does not export any symbols. Simply requiring it once is enough; subsequent requires of .sql files will then work.

Demonstrates how to enable .sql file loading via require() and use the resulting string.

// Install: npm install require-sql // Enable .sql file support (side-effect import) require('require-sql'); // Now you can require .sql files const query = require('./some-query.sql'); // The contents are returned as a plain string console.log(query); // Output: SELECT * FROM my_table
Debug
Known issues
gotcharequire('require-sql') must be called exactly once before requiring any .sql files; it modifies global require.extensions.
fix
Ensure the side-effect require is executed at the start of your application entry point.
affects: 1.0.0
gotchaThis package only works with CommonJS require, not ESM import. It relies on require.extensions which is not available in Node.js ESM modules.
fix
Use ESM or dynamic imports if you need to load SQL files in ESM context; consider using fs.readFileSync instead.
affects: 1.0.0
gotchaThe package has no TypeScript type definitions. Using it in a TypeScript project will result in an error if not handled.
fix
Create a declaration file (e.g., declare module '*.sql' { const content: string; export default content; }) or use raw fs.readFile.
affects: 1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'require-sql'
The package is not installed in node_modules.
fix
Run npm install require-sql --save
TypeError: require(...) is not a function
Attempting to use the return value of require('require-sql') as a function.
fix
require('require-sql') returns an empty object; do not assign it to a variable expecting a function.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
6
Meta
1
Resources
require-sql — npm install require-sql · libregistry