@google-cloud/language

The @google-cloud/language package has the following named exports:

Source:
Examples

Install the client library with npm:

npm install --save @google-cloud/language

Import the client library:

const language = require('@google-cloud/language');

Create a client that uses Application Default Credentials (ADC):

const client = new language.LanguageServiceClient();

Create a client with explicit credentials:

const client = new language.LanguageServiceClient({
  projectId: 'your-project-id',
  keyFilename: '/path/to/keyfile.json',
});

Full quickstart example:

async function quickstart() {
  // Imports the Google Cloud client library
  const language = require('@google-cloud/language');

  // Instantiates a client
  const client = new language.LanguageServiceClient();

  // The text to analyze
  const text = 'Hello, world!';

  const document = {
    content: text,
    type: 'PLAIN_TEXT',
  };

  // Detects the sentiment of the text
  const [result] = await client.analyzeSentiment({document: document});
  const sentiment = result.documentSentiment;

  console.log(`Text: ${text}`);
  console.log(`Sentiment score: ${sentiment.score}`);
  console.log(`Sentiment magnitude: ${sentiment.magnitude}`);
}

Members

(static) v1 :object

Properties:
Name Type Description
LanguageServiceClient constructor

Reference to v1.LanguageServiceClient

Source:

(static) v1beta2 :object

Properties:
Name Type Description
LanguageServiceClient constructor

Reference to v1beta2.LanguageServiceClient

Source: