MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/nodejs-docs-samples / setEndpoint

Function setEndpoint

cloud-language/setEndpoint.js:17–44  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

15'use strict';
16
17async function setEndpoint() {
18 // [START language_set_endpoint]
19 // Imports the Google Cloud client library
20 const language = require('@google-cloud/language');
21
22 // Specifies the location of the api endpoint
23 const clientOptions = {apiEndpoint: 'eu-language.googleapis.com'};
24
25 // Instantiates a client
26 const client = new language.LanguageServiceClient(clientOptions);
27 // [END language_set_endpoint]
28
29 // The text to analyze
30 const text = 'Hello, world!';
31
32 const document = {
33 content: text,
34 type: 'PLAIN_TEXT',
35 };
36
37 // Detects the sentiment of the text
38 const [result] = await client.analyzeSentiment({document: document});
39 const sentiment = result.documentSentiment;
40
41 console.log(`Text: ${text}`);
42 console.log(`Sentiment score: ${sentiment.score}`);
43 console.log(`Sentiment magnitude: ${sentiment.magnitude}`);
44}
45
46setEndpoint().catch(console.error);

Callers 1

setEndpoint.jsFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected