Basic authenticationedit

You can provide your credentials by passing the username and password parameters via the auth option.

If you provide both basic authentication credentials and the Api Key configuration, the Api Key will take precedence.

const { Client } = require('@elastic/elasticsearch')
const client = new Client({
  node: 'https://localhost:9200',
  auth: {
    username: 'elastic',
    password: 'changeme'
  }
})

Otherwise, you can provide your credentials in the node(s) URL.

const { Client } = require('@elastic/elasticsearch')
const client = new Client({
  node: 'https://username:password@localhost:9200'
})