npm installbecause IBM delivers a DB2 adapter/driver with Node.js. The DB2 adapter/driver doesn't actually exist on npmjs.com so it couldn't be installed in that fashion anyway.
% node sql.js
error: undefinedor similar in your console that means there wasn't an error specified in the error return field.
db2a.jsfile lives in the IFS. Note you can omit the
require(...)will assume that extension. The
db.conn("*LOCAL")will connect to the local database and use the profile this script is running under for authorization. You could also specify a different profile and password.
stmt.exec(...)lines are where the action happens. You'll notice the
stmt.execstatements were one after each other then that would mean they would be invoked concurrently. That would obviously be an issue in this case because we can't
INSERTa row before the
CREATE TABLEis complete.
systablesis performed so we can learn whether the
CREATE TABLEwas successful. You should see output similar to the following. I have formatted the below output so it is easier to decipher.
CUSTOMERtable. Below is the modified
res.send(...)we are using
res.json(...). This will change the
Content-typeheader that's sent back down to the client, among other things. I did this to introduce you to another way to send a response.
index.jsfile and then start your application again, as shown below.