index.js 983 Bytes
var express = require('express');
var router = express.Router();
const { PythonShell } = require('python-shell');
var pyshell = new PythonShell("all_data.py");




/* GET home page. */
router.get('/', function(req, res ) {

  res.render('index');

});
router.post('/', function(req,res){
  console.log(req.body.userid); //  req.body.userid를 받아옴

  pyshell.send(JSON.stringify(req.body.userid));//the problem function

  pyshell.on('message', function (row) {
    // received a message sent from the Python script (a simple "print" statement)

    console.log(row);
    return  res.render('show', { userid:req.body.userid, data:JSON.parse(row)});


  });

// end the input stream and allow the process to exit
  pyshell.end(function (err,) {
    if (err){
      throw err;
    };

    console.log('finished');
  });

});

router.get('show', function (req,res){


    console.log(row);
    res.render('show' ,{userid:req.body.userid, data:row});


});
module.exports = router;