I started to develop a small cahtbot with IBM technology (Watson), I'm using NodeJS for the development part of the application. I am using Express as a routing framework, I have also divided the project into views, routes and the server. I found the following error, I have my route as we can see:
const express = require('express');
const router = express.Router();
router.post('/conversation/', (req, res) => {
const { text, context = {} } = req.body;
const params = {
input: { text },
workspace_id:'Workspace-id',
context,
};
assistant.message(params, (err, response) => {
if (err) res.status(500).json(err);
res.json(response);
});
});
module.exports = router;
My Server is in the following way:
/*eslint-env node*/
'use strict';
// This application uses express as its web server
// for more info, see: http://expressjs.com
const express = require('express');
const bodyParser = require('body-parser');
const path = require('path');
// cfenv provides access to your Cloud Foundry environment
// for more info, see: https://www.npmjs.com/package/cfenv
const cfenv = require('cfenv');
// create a new express server
const app = express();
const AssistantV1 = require('watson-developer-cloud/assistant/v1');
const assistant = new AssistantV1({
username: 'username',
password: 'pass',
url: 'https://gateway.watsonplatform.net/assistant/api/',
version: '2018-02-16',
});
//Configuring the environment
//Use body-parser to nodejs understand the user requests
app.use(bodyParser.urlencoded({extended:false}));
app.use(bodyParser.json());
//establish the views directory
app.set('views',path.join(__dirname,'views')); //__dirname get the main tab project
//establish the views engine
app.set('view engine','ejs');
// serve the files out of ./public as our main files
app.use(express.static(__dirname + '/public'));
// get the app environment from Cloud Foundry
var appEnv = cfenv.getAppEnv();
//Routes
app.use('/', require('./routes/index'));
// start server on the specified port and binding host
app.listen(appEnv.port, appEnv.bind, () => {
// print a message when the server starts listening
console.log("server starting on " + appEnv.url);
});
Now what I want is to start my server in the link link
When I enter it from the browser, I get the following error:
I'm new with NodeJS so, I do not know what I'm doing wrong, the weird thing is that with the GET method I do not have the same problem and if you send me the render of the index.ejs.