Node.js初心者です。
windows環境でNode.jsを使ってoracleを読み取り、外部のjavascriptファイルから利用したいのですが、詰まってしまいました。
nmpでnode-oracledbをインストールして、githubのサンプルを流用した以下のようなコードで結果を読み取るまでは成功しました。
javascript
1// https://github.com/oracle/node-oracledb/blob/master/examples/select1.js#L35 2 3var oracledb = require('oracledb'); 4 5oracledb.getConnection( { 6 user : "user", 7 password : "password", 8 connectString : "connectString" 9 }, 10 function(err, connection) { 11 if (err) { 12 console.error(err.message); 13 return; 14 } 15 connection.execute( 16 `SELECT department_id, department_name 17 FROM departments WHERE department_id = :id`, 18 [180], 19 { 20 maxRows: 1 21 }, 22 23 function(err, result) { 24 if (err) { 25 console.error(err.message); 26 doRelease(connection); 27 return; 28 } 29 // 成功時 30 const kekka = result.rows; 31 doRelease(connection); 32 console.log(kekka); 33 }); 34}); 35 36function doRelease(connection) { 37 connection.close( 38 function(err) { 39 if (err) { 40 console.error(err.message); 41 } 42 }); 43} 44
しかし、表示した結果を外部から参照するのに試行錯誤するのですがうまくいきません。変数を用意してexports.をつけるのが良いのか、なんらかの関数を外部から利用できるようにするのがよいのかわかりません。何が問題でどうすれば良いでしょうか。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/01/30 07:50