Thursday, 11 May 2017

app.get('') is not working in node js with query parameters

Iam trying to provide a new route for my conversation application where it should accept the parameters passed along with the route should be accepted and can be used in client side.But I couldnt figure out why basic .get() is not working ,where Iam unable to render the html.

'use strict';
var express = require('express'); // app server
var bodyParser = require('body-parser'); // parser for post requests
var Conversation = require('watson-developer-cloud/conversation/v1'); // watson sdk
var bodyParser = require('body-parser');
var app = express();
app.use(express.static('./public')); // load UI from public folder
app.use(bodyParser.json());
app.get('/:id',function(req,res){
     var userid = req.param.id;
     var pid = req.query.pid;
     res.sendFile(__dirname,'/public/index.html');
});
module.exports = app;

On my localhost:3000 index file is getting loaded but for something like localhost:3000/3405?pid=CBM it is not loading.

Then I have a js file on client side which would require these two values id and pid.For now I just hardcoded.But how can I use these values to client side js file..Can someone help me how can I do this... Thanks



via user7350714

No comments:

Post a Comment