Help us understand the problem. What is going on with this article?

Twitter の Bearer Token を取得 (Node.js)

Consumer Key (API Key) と、Consumer Secret (API Secret) を使って、Bearer Token を取得する方法です。
.env ファイルにキーを入れます。

get_bearer.js
#! /usr/bin/node
// ---------------------------------------------------------------
//  get_bearer.js
//
//                      Apr/25/2019
// ---------------------------------------------------------------
const request = require('request');
const dotenv = require('dotenv');
//
dotenv.config()
const consumer_key = `${process.env.CONSUMER_KEY}`
const consumer_secret = `${process.env.CONSUMER_SECRET}`
//
const credentials = consumer_key + ":" + consumer_secret
const credentialsBase64Encoded = (Buffer.from(credentials)).toString('base64')

console.error ("*** 開始 ***")

request({
    url: 'https://api.twitter.com/oauth2/token',
    method:'POST',
    headers: {
      'Authorization': `Basic ${credentialsBase64Encoded}`,
      'Content-Type':'application/x-www-form-urlencoded;charset=UTF-8'
    },
    body: 'grant_type=client_credentials'
}, function(err, resp, body) {
    console.log(body)
    console.error ("*** 終了 ***")
})

// ---------------------------------------------------------------
.env
CONSUMER_KEY = '******'
CONSUMER_SECRET = '***********'
Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away