我正在创建一个小的Restful Api应用程序,我使用了expres4-tedious并快速构建了这个应用程序。
我的应用程序成功启动,但是当我通过邮递员请求“ / users”路径时,收到以下错误消息:
tedious deprecated In the next major version of `tedious`, creating a new `Connection` instance will no longer establish a connection to the server automatically. Please use the new `connect` helper function or call the `.connect` method on the newly created `Connection` object to silence this message. internal\process\task_queues.js:75:11
(node:5472) [DEP0123] DeprecationWarning: Setting the TLS ServerName to an IP address is not permitted by RFC 6066. This will be ignored in a future version.
_http_outgoing.js:618
throw new ERR_INVALID_ARG_TYPE('first argument',
^
TypeError [ERR_INVALID_ARG_TYPE]: The first argument must be one of type string or Buffer. Received type number
at write_ (_http_outgoing.js:618:11)
at ServerResponse.write (_http_outgoing.js:586:15)
at Request.<anonymous> (D:\Huy's Work\NodeJS\HelloWorld\node_modules\express4-tedious\index.js:35:29)
at Request.emit (events.js:210:5)
at Parser.<anonymous> (D:\Huy's Work\NodeJS\HelloWorld\node_modules\tedious\lib\connection.js:1014:21)
at Parser.emit (events.js:210:5)
at Parser.<anonymous> (D:\Huy's Work\NodeJS\HelloWorld\node_modules\tedious\lib\token\token-stream-parser.js:37:14)
at Parser.emit (events.js:210:5)
at addChunk (D:\Huy's Work\NodeJS\HelloWorld\node_modules\readable-stream\lib\_stream_readable.js:298:12)
at readableAddChunk (D:\Huy's Work\NodeJS\HelloWorld\node_modules\readable-stream\lib\_stream_readable.js:280:11) {
code: 'ERR_INVALID_ARG_TYPE'
}
我的package.json:
{
"name": "helloworld",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "nodemon server.js"
},
"author": "",
"license": "ISC",
"devDependencies": {
"nodemon": "^2.0.4"
},
"dependencies": {
"body-parser": "^1.19.0",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"express4-tedious": "^0.3.0",
"tedious": "^8.3.0"
}
}
我在第35行检查了文件express4-tedious \ index.js,在命令中看到错误消息:“ ostream.write(列[0] .value);” 我的server.js文件:
const express = require('express')
const app = express()
const bodyParser = require('body-parser')
const port = process.env.PORT || 3000
var tediousExpress = require('express4-tedious');
require('dotenv').config()
app.use(bodyParser.urlencoded({ extended: true }))
app.use(bodyParser.json())
// let routes = require('./api/routes') //importing route
app.use((req, res, next) => {
req.sql = tediousExpress({
"server": "server",
"authentication": {
"type": "default",
"options": {
"userName": "sa",
"password": "password"
}
},
"options": {
"encrypt": true,
"database": "dc_new_db",
"trustServerCertificate":true,
"cryptoCredentialsDetails": {
"minVersion": 'TLSv1'
}
}
});
next();
})
app.get('/users', (request, response) => {
request.sql("select * from CheckAward")
.into(response, '[]');
});
// routes(app)
app.use((req, res) => {
res.status(404).send({ url: req.originalUrl + ' not found' })
})
app.listen(port);
希望每个人都帮助我!