Snippets

litmis ITJungle.com Article: Customer Listing HTML and Node.js

Created by Aaron Bartell last modified Andrei Tyuhai
<!DOCTYPE html>
<html>
  <head>
    <title>List Customers</title>
    <link rel="stylesheet" href="http://cdn.webix.com/edge/webix.css" type="text/css"> 
    <script src="http://cdn.webix.com/edge/webix.js" type="text/javascript"></script>
  </head>
  <body>
    <h2>Customer Listing</h2>
    <div id="list_div"></div>
    
    <script type="text/javascript" charset="utf-8">
    webix.ready(function(){
      grida = webix.ui({
        container:"list_div",
        view:"datatable",
        columns:[
          { id:"CUSNUM", header:"Number", css:"rank"},
          { id:"LSTNAM", header:[ "Last Name",{content:"textFilter"}], css:"rank"},
          { id:"CITY", header:"City"},
          { id:"CDTLMT", header:"Credit Limit"}
        ],
        autoheight:true,
        autowidth:true,
        url:"/data"
      });           
    });
    </script>
    
  </body>
</html>
var db = require('/QOpenSys/QIBM/ProdData/Node/os400/db2i/lib/db2')
var express = require('express')
var app = express()
var bodyParser = require('body-parser')
var serveStatic = require('serve-static')

app.use(serveStatic('public', {index: ['list_customers.html']}))
app.use(bodyParser.urlencoded({ extended: false }))

db.init()
db.conn("*LOCAL")

app.get('/data', function(req, res){
  db.exec("SELECT * FROM QIWS.QCUSTCDT", function(result) {
    res.send(result)
  });
    
});

var port = process.env.PORT || 8080
app.listen(port)
console.log('Running on port %d', port)

Comments (0)