-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
46 lines (35 loc) · 1.04 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const bodyParser = require('body-parser');
const express = require('express');
const language = require('@google-cloud/language');
const app = express();
app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json());
// Instantiates a client
const client = new language.LanguageServiceClient({
credentials: {
}
});
app.post('/', function (req, res) {
const document = {
content: JSON.stringify(req.body),
type: 'PLAIN_TEXT',
};
client
.analyzeSentiment({document: document})
.then(results => {
const sentiment = results[0].documentSentiment;
console.log(`Sentiment magnitude: ${sentiment.magnitude}`);
let response = {
"status": 200,
"mag": ""
};
response.mag = sentiment.magnitude;
res.send(response)
})
.catch(err => {
console.error('ERROR:', err);
});
});
app.listen(3000, function () {
console.log('Server Started on Port 3000...');
});