1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

IBM i (AS/400)のPASE環境でnode.jsを動かす方法 [IBM i Native Objectアクセス編] (4/4)

Last updated at Posted at 2018-07-17

nodejsi.png

#1.JavaScriptの準備
##IBM i Native ObjectをアクセスするJavaScriptを作成して動作確認
###【Javaスクリプトの編集】
テキストエディターでJavaScriptを編集後、UTF-8で「sample2.js」と名前を付けて保存

hello.js
var http = require('http');
var db = require('/QOpenSys/QIBM/ProdData/Node/os400/db2i/lib/db2');
var xt = require('/QOpenSys/QIBM/ProdData/Node/os400/xstoolkit/lib/itoolkit');
var pd = require('/QOpenSys/QIBM/ProdData/Node/os400/xstoolkit/lib/iprod');
var prod = new pd.iProd(new xt.iConn("S6515E9A"));
var prodInfo = prod.getProductInfo("5770DG1");
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
db.init();
db.conn("S6515E9A");
db.exec("SELECT LSTNAM, STATE FROM QIWS.QCUSTCDT", function(rs) {
res.write("Product ID:" + prodInfo["Product_ID"] + "\n");
res.write("Release level:" + prodInfo["Release_level"] + "\n");
res.write("Load State:" + prodInfo["Symbolic_load_state"] + "\n");
res.end(JSON.stringify(rs));
});
db.close();
}).listen(8082, '192.168.1.7');
console.log('Server running at http://192.168.1.7:8082/');

###【FTP転送】
先にIBM iに作成済みの/home/nodeフォルダーへ「sample2.js」をFTP転送
nodejs04_02.png

#2.JavaScriptの実行
##「sample2.js」JavaScriptを実行して動作確認
###【実行コマンド】

CALL QP2TERM
cd /QOpenSys/QIBM/ProdData/Node/bin
node /home/node/sample2.js

nodejs04_05.png

###【実行結果】
ソース上で指定したIPアドレスとポートでWebブラウザからアクセスした物理ファイルから意図する結果が得られたことから正しく動作しているといえます。
nodejs04_06.png

この記事を読んでいただいてありがとうございます!

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?