Reputation: 13
I am trying to build a sentiment analysis bot with IBM Watson for slack. https://api.slack.com/tutorials/watson-sentiment#setting_up_your_request_url
I got stuck quite early, as when running the node script of index.js, I keep getting this error:
SyntaxError: Unexpected token 'const'
at wrapSafe (internal/modules/cjs/loader.js:1053:16)
at Module._compile (internal/modules/cjs/loader.js:1101:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
at Module.load (internal/modules/cjs/loader.js:985:32)
at Function.Module._load (internal/modules/cjs/loader.js:878:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
at internal/main/run_main_module.js:17:47
(base) ndaa-qtn3118-mbp:sentimentapp qtn3118$ nano index.js
(base) ndaa-qtn3118-mbp:sentimentapp qtn3118$ node index.js
/Users/qtn3118/sentimentapp/index.js:6
const server = app.listen(5000, () => {
^^^^^
SyntaxError: Unexpected token 'const'
at wrapSafe (internal/modules/cjs/loader.js:1053:16)
at Module._compile (internal/modules/cjs/loader.js:1101:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
at Module.load (internal/modules/cjs/loader.js:985:32)
at Function.Module._load (internal/modules/cjs/loader.js:878:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
at internal/main/run_main_module.js:17:47
I checked my code with the example github, and it doesn't look like I have any typos, here is the .js file:
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
...
const server = app.listen(5000, () => {
console.log('Express server listening on port %d in %s mode', server.address().port, app.settings.env);});
app.post('/event', (req, res) => {
if (req.body.type === 'url_verification') {
res.send(req.body.challenge);
}});
Upvotes: 0
Views: 66
Reputation: 13
In order to connect and verify with Slack API this had to be added:
app.use(bodyParser.json());
Upvotes: 1
Reputation: 868
the "..." on the 4th line is not supposed to be in your actual code. It's just a shorthand for you to delete, meaning that other libraries or variable definitions could appear there.
Just remove the "..."
Upvotes: 0