Microsoft SQL Server client for Node.js
翻訳待ち
開発ツールJavaScript · TSQLGitHub @tediousjs自分でインストール所有者未確認
Paste into Claude or ChatGPT for installation instructions suited to your environment.
Have you tried it? One tap is enough. No sign-in needed.
The maker's introduction consists of the line above. Read the repository README for more details. Repository README ↗
Loading the full README.
Read the full README ↗Microsoft SQL Server client for Node.js
Supported TDS drivers:
npm install mssql
npm install mssql msnodesqlv8
msnodesqlv8 6 needs Node.js 22 or later. On an older Node.js, install msnodesqlv8 5 (npm install mssql msnodesqlv8@5).
This package requires TCP/IP to connect to SQL Server, and you may need to enable this in your installation.
const sql = require('mssql')
(async () => {
try {
// make sure that any items are correctly URL encoded in the connection string
await sql.connect('Server=localhost,1433;Database=database;User Id=username;Password=password;Encrypt=true')
const result = await sql.query`select * from mytable where id = ${value}`
console.dir(result)
} catch (err) {
// ... error checks
}
})()
If you're on Windows Azure, add ?encrypt=true to your connection string. See docs to learn more.
Parts of the connection URI should be correctly URL encoded so that the URI can be parsed correctly.
Assuming you have set the appropriate environment variables, you can construct a config object as follows:
const sql = require('mssql')
const sqlConfig = {
user: process.env.DB_USER,
password: process.env.DB_PWD,
database: process.env.DB_NAME,
server: 'localhost',
pool: {
max: 10,
min: 0,
idleTimeoutMillis: 30000
},
options: {
encrypt: true, // for azure
trustServerCertificate: false // change to true for local dev / self-signed certs
}
}
(async () => {
try {
// make sure that any items are correctly URL encoded in the connection string
await sql.connect(sqlConfig)
const result = await sql.query`select * from mytable where id = ${value}`
console.dir(result)
} catch (err) {
// ... error checks
}
})()
const sql = require('mssql/msnodesqlv8');
const config = {
server: "MyServer",
database: "MyDatabase",
options: {
trustedConnection: true, // Set to true if using Windows Authentication
trustServerCertificate: true, // Set to true if using self-signed certificates
},
// driver: "ODBC Driver 18 for SQL Server", // Uncomment to use specific driver
};
(async () => {
try {
await sql.connect(config);
const result = await sql.query`select TOP 10 * from MyTable`;
console.dir(result);
} catch (err) {
console.error(err);
}
})();
const config = {
user: '...',
password: '...',
server: 'localhost', // You can use 'localhost\\instance' to connect to named instance
database: '...',
}
This is the beginning of the README. Read the rest at the original. Read the full README ↗