Performs label detection on a local document file.

## Explore further


For detailed documentation that includes this code sample, see the following:

- [Label detection on a local file](https://docs.cloud.google.com/vision/docs/samples/vision-detect-document)

## Code sample

### Node.js


To learn how to install and use the client library for Vision API Product Search, see
[Vision API Product Search client libraries](https://docs.cloud.google.com/vision/product-search/docs/libraries).


For more information, see the
[Vision API Product Search Node.js API
reference documentation](https://googleapis.dev/nodejs/vision/latest).


To authenticate to Vision API Product Search, set up Application Default Credentials.
For more information, see

[Set up authentication for a local development environment](https://docs.cloud.google.com/docs/authentication/set-up-adc-local-dev-environment).

    // Imports the Google Cloud client libraries
    const vision = require('https://docs.cloud.google.com/nodejs/docs/reference/vision/latest/overview.html').v1p1beta1;

    // Creates a client
    const client = new vision.https://docs.cloud.google.com/nodejs/docs/reference/vision/latest/overview.html();

    /**
     * TODO(developer): Uncomment the following line before running the sample.
     */
    // const fileName = 'Local image file, e.g. /path/to/image.png';

    // Performs label detection on the local file
    const [result] = await client.textDetection(fileName);
    const pages = https://docs.cloud.google.com/nodejs/docs/reference/vision/latest/vision/protos.google.longrunning.operation.html.fullTextAnnotation.pages;
    pages.forEach(page => {
      page.blocks.forEach(block => {
        const blockWords = [];
        block.paragraphs.forEach(paragraph => {
          paragraph.words.forEach(word => blockWords.push(word));
          console.log(`Paragraph confidence: ${paragraph.confidence}`);
        });

        let blockText = '';
        const blockSymbols = [];
        blockWords.forEach(word => {
          word.symbols.forEach(symbol => blockSymbols.push(symbol));
          let wordText = '';
          word.symbols.forEach(symbol => {
            wordText = wordText + symbol.text;
            console.log(`Symbol text: ${symbol.text}`);
            console.log(`Symbol confidence: ${symbol.confidence}`);
          });
          console.log(`Word text: ${wordText}`);
          console.log(`Word confidence: ${word.confidence}`);
          blockText = blockText + ` ${wordText}`;
        });

        console.log(`Block text: ${blockText}`);
        console.log(`Block confidence: ${block.confidence}`);
      });
    });

## What's next


To search and filter code samples for other Google Cloud products, see the
[Google Cloud sample browser](https://docs.cloud.google.com/docs/samples?product=cloudvision).