I need GCC 4.7 (or higher) for installation.
Because compiling node 4 (or later) requires a C + + 11-compliant compiler. The default compilers on Linux 6 and Rhel 6 do not have the required C + + 11 support. Install GCC 4.7 or later or upgrade to Linux 7. (Click to view the official install C + + 11 tutorial) or refer to the CentOS Yum upgrade gcc to 4.8 tutorial.
Note: After installation, verify the version:
gcc --version
Second, installation Nodejs
Install with version 6.9.4 (depending on the version reference)
CD/opttar -jxf node-v6. 9.4-linux-x64. tar. XZ
To set the node. JS environment variable:
Export PATH=/OPT/NODE-V6. 9.4-linux-x64/bin: $PATH
View Node version
Node-v
III. Installing the Oracle client ' Basic ' and ' SDK ' zip packages
Enter, download the following two packages and install them in the same directory
Take the native test as an example, my installation location (customizable) is/opt/oracle
cd/opt/Oracleunzip instantclient-basic-linux.x64-12.2. 0.1. 0. Zip Unzip instantclient-sdk-linux.x64-12.2. 0.1. 0. Zip MV instantclient_12_2 INSTANTCLIENTCD instantclient Ln -S libclntsh.so. 12.1 libclntsh.so
Setting environment variables
Export ld_library_path=/opt/oracle/instantclient: $LD _library_pathexport oci_lib_dir=/opt/oracle/ Instantclientexport Oci_inc_dir=/opt/oracle/instantclient/sdk/include
Iv. Installation of OracleDB test
To install the Oracle library:
Install OracleDB
Output:
> [email protected] Install/opt/oracletest/node_modules/oracledb
> Node-gyp Rebuild
make:entering directory '/opt/oracletest/node_modules/oracledb/build '
CXX (target) RELEASE/OBJ.TARGET/ORACLEDB/SRC/NJS/SRC/NJSORACLE.O
CXX (target) RELEASE/OBJ.TARGET/ORACLEDB/SRC/NJS/SRC/NJSPOOL.O
CXX (target) RELEASE/OBJ.TARGET/ORACLEDB/SRC/NJS/SRC/NJSCONNECTION.O
CXX (target) RELEASE/OBJ.TARGET/ORACLEDB/SRC/NJS/SRC/NJSRESULTSET.O
CXX (target) RELEASE/OBJ.TARGET/ORACLEDB/SRC/NJS/SRC/NJSMESSAGES.O
CXX (target) RELEASE/OBJ.TARGET/ORACLEDB/SRC/NJS/SRC/NJSINTLOB.O
CXX (target) RELEASE/OBJ.TARGET/ORACLEDB/SRC/DPI/SRC/DPIENV.O
CXX (target) RELEASE/OBJ.TARGET/ORACLEDB/SRC/DPI/SRC/DPIENVIMPL.O
CXX (target) RELEASE/OBJ.TARGET/ORACLEDB/SRC/DPI/SRC/DPIEXCEPTION.O
CXX (target) RELEASE/OBJ.TARGET/ORACLEDB/SRC/DPI/SRC/DPIEXCEPTIONIMPL.O
CXX (target) RELEASE/OBJ.TARGET/ORACLEDB/SRC/DPI/SRC/DPICONNIMPL.O
CXX (target) RELEASE/OBJ.TARGET/ORACLEDB/SRC/DPI/SRC/DPIDATETIMEARRAYIMPL.O
CXX (target) RELEASE/OBJ.TARGET/ORACLEDB/SRC/DPI/SRC/DPIPOOLIMPL.O
CXX (target) RELEASE/OBJ.TARGET/ORACLEDB/SRC/DPI/SRC/DPISTMTIMPL.O
CXX (target) RELEASE/OBJ.TARGET/ORACLEDB/SRC/DPI/SRC/DPIUTILS.O
CXX (target) RELEASE/OBJ.TARGET/ORACLEDB/SRC/DPI/SRC/DPILOB.O
CXX (target) RELEASE/OBJ.TARGET/ORACLEDB/SRC/DPI/SRC/DPICOMMON.O
Solink_module (target) Release/obj.target/oracledb.node
COPY Release/oracledb.node
make:leaving directory '/opt/oracletest/node_modules/oracledb/build '
NPM WARN saveerror enoent:no such file or directory, open '/opt/oracletest/package.json '
NPM notice created a lockfile as Package-lock.json. You should commit the this file.
NPM WARN enoent enoent:no such file or directory, open '/opt/oracletest/package.json '
NPM WARN oracletest No Description
NPM WARN oracletest No repository field.
NPM WARN oracletest No README data
NPM WARN oracletest No license field.
+ [email protected]
Added 2 packages in 42.994s
To create a new app.js test connection in the current directory:
varOracleDB = require (' OracleDB '));varConfig ={User:‘******‘,//user name password:‘******‘,//password
IP: Database IP address, port: Database ports, SCHEMA: Database name connectstring:"Ip:port/schema"};oracledb.getconnection (config,function(err, connection) {if(Err) {console.error (err.message); return; }
Query a table 10 data test, pay attention to replace your table name Connection.Execute ("SELECT * FROM (select A.*, ROWNUM rn from (SELECT * from your table name) A where ROWNUM <=) where RN >= 0", function(err, result) {if(Err) {console.error (err.message); Dorelease (connection); return; } //Print the returned table structureConsole.log (Result.metadata); //Print the returned row dataConsole.log (result.rows); }); });functionDorelease (connection) {Connection.close (function(err) {if(Err) {console.error (err.message); } });}
Perform:
Node App.js
Error after execution:
Ora-24454:client host name is not set
Here you need to set the hostname to/etc/hosts
sudo " echo ' 127.0.1.1 ${hostname} ' >>/etc/hosts "
After setting the re-execution node app.js returns the print result successfully.
Reference Https://github.com/oracle/node-oracledb/blob/master/INSTALL.md#instzip
Linux Nodejs using the official OracleDB Library Connection Database Tutorial