Tedious is a pure-Javascript implementation of the TDS protocol, which is used to interact with instances of Microsoft's SQL Server. It is intended to be a fairly slim implementation of the protocol, with not too much additional functionality.
See the changelog for version history.
- TDS 8.0 (SQL Server 2022 and later; requires
options.encrypt: 'strict') - TDS 7.4 (SQL Server 2012/2014/2016/2017/2019/2022/2025)
- TDS 7.3.B (SQL Server 2008 R2)
- TDS 7.3.A (SQL Server 2008)
- TDS 7.2 (SQL Server 2005)
- TDS 7.1 (SQL Server 2000) - deprecated, support will be removed in a future version
Tedious requires Node.js 22 or later. Install the package with:
npm install tediousPlatform-specific guides are available for:
- Node.js SQL Server Guide
- Node.js + macOS
- Node.js + Red Hat Enterprise Linux
- Node.js + SUSE Linux Enterprise Server
- Node.js + Ubuntu
- Node.js + Windows
Create a connection using your SQL Server host and credentials, then execute a request. This example reads credentials from environment variables; set them before running the script.
const { Connection, Request } = require('tedious');
const connection = new Connection({
server: process.env.DB_SERVER,
authentication: {
type: 'default',
options: {
userName: process.env.DB_USER,
password: process.env.DB_PASSWORD
}
},
options: {
database: process.env.DB_DATABASE
}
});
connection.on('error', (error) => {
console.error('Connection error:', error);
});
connection.connect((error) => {
if (error) {
console.error('Connection failed:', error);
return;
}
const request = new Request('SELECT 1 AS value', (error) => {
if (error) {
console.error('Query failed:', error);
}
connection.close();
});
request.on('row', (columns) => {
console.log(columns[0].value);
});
connection.execSql(request);
});Encryption and server certificate validation are enabled by default. Local or
Docker SQL Server instances often use self-signed certificates; for development
only, set trustServerCertificate: true in options to bypass certificate validation.
For TDS 8.0 with SQL Server 2022 or later, set encrypt: 'strict' in options;
leave tdsVersion at its default. Strict encryption requires a
valid server certificate; trustServerCertificate does not bypass certificate
validation in this mode. See the
API documentation and
examples for more options and usage patterns.
More documentation and code samples are available at tediousjs.github.io/tedious/
Tedious is simply derived from a fast, slightly garbled, pronunciation of the letters T, D and S.
We welcome contributions from the community. Feel free to check out the code and submit pull requests.
Please report security vulnerabilities privately. See our security policy for reporting instructions.
Copyright (c) 2010-2026 Mike D Pilsbury
The MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.