NodeJs

1.创建NodejsDemo作为项目目录,使用 npm init 创建NodeJs的配置文件 package.json
G:\NodejsProject\NodejsDemo>npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.

See `npm help init` for definitive documentation on these fields
and exactly what they do.

Use `npm install <pkg>` afterwards to install a package and
save it as a dependency in the package.json file.

Press ^C at any time to quit.
package name: (nodejsdemo)
version: (1.0.0)
description:
entry point: (index.js)
test command:
git repository:
keywords:
author:
license: (ISC)
About to write to G:\NodejsProject\NodejsDemo\package.json:

{
"name": "nodejsdemo",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}

Is this OK? (yes)
2.把highgodb 和pg-protocol模块包拷贝至工程根目录

链接:https://pan.baidu.com/s/1xuz6uJz0utRgKWecXhpOiA?pwd=o0tj

3.修改package.json文件,在package.json文件中,添加模块引用
{
"name": "nodejsdemo",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"highgodb": "file:./highgodb",
"pg-protocol": "file:./pg-protocol"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
4.安装模块依赖包 npm install
G:\NodejsProject\NodejsDemo>npm install
npm WARN deprecated debug@3.2.6: Debug versions >=3.2.0 <3.2.7 || >=4 <4.3.1 have a low-severity ReDos regression when used in a Node.js environment. It is recommended you upgrade to 3.2.7 or 4.3.1. (https://github.com/visionmedia/debug/issues/797)

added 205 packages, and audited 208 packages in 24s

60 packages are looking for funding
run `npm fund` for details

5 vulnerabilities (1 low, 1 high, 3 critical)

To address all issues (including breaking changes), run:
npm audit fix --force

Run `npm audit` for details.
5.创建测试表,写入数据
CREATE TABLE nodejs_test(id int,jsname varchar(10));
Insert into nodejs_test values (1,'nodejs-sm3');
6.编写测试 hgdbsm3.js
const { Pool, Client } = require('highgodb')
////使用连接池的方式
//const pool = new Pool({
// user: 'sysdba',
// host: '192.168.100.101',
// database: 'highgo',
// password: 'Qwer@1234',
// password: 'Qwer@1234',
// port: 5866,
//})
//pool.query('select * from nodejs_test;', (err, res) => {
// console.log(err, res)
// pool.end()
//})

//使用 client 方式
const client = new Client({
host: '192.168.100.101',
user: "sysdba",
password: "Qwer@1234",
database: "highgo",
port: 5866,
})
client.connect()
client.query('select * from nodejs_test;', (err, res) => {
console.log(err, res)
client.end()
})

console.log('Press any key to exit');

process.stdin.setRawMode(true);
process.stdin.resume();
process.stdin.on('data', process.exit.bind(process, 0));
7.node ./hgdbsm3.js
G:\NodejsProject\NodejsDemo>node ./hgdbsm3.js
Press any key to exit
null Result {
command: 'SELECT',
rowCount: 1,
oid: null,
rows: [ { id: 1, jsname: 'nodejs-sm3' } ],
fields: [
Field {
name: 'id',
tableID: 1065313,
columnID: 1,
dataTypeID: 23,
dataTypeSize: 4,
dataTypeModifier: -1,
format: 'text'
},
Field {
name: 'jsname',
tableID: 1065313,
columnID: 2,
dataTypeID: 1043,
dataTypeSize: -1,
dataTypeModifier: 14,
format: 'text'
}
],
_parsers: [ [Function: parseInteger], [Function: noParse] ],
_types: TypeOverrides {
_types: {
getTypeParser: [Function: getTypeParser],
setTypeParser: [Function: setTypeParser],
arrayParser: [Object],
builtins: [Object]
},
text: {},
binary: {}
},
RowCtor: null,
rowAsArray: false
}