Node.js에서 LINE Notify를 사용하는 메모

htps : // 후 fy 보 t. 네. 메/my/ 에서 액세스 토큰을 발행합니다.



준비


npm init -y
npm i --save axios

코드



app.js
'use strcit';

const axios = require('axios');
const qs = require('querystring');
const BASE_URL = 'https://notify-api.line.me';
const PATH =  '/api/notify';
const LINE_TOKEN = `アクセストークン`;

let config = {
    baseURL: BASE_URL,
    url: PATH,
    method: 'post',
    headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
        'Authorization': `Bearer ${LINE_TOKEN}`
    },
    data: qs.stringify({
        message: `こんばんわ`,
    })
};

axios.request(config)
.then((res) => {
    console.log(res.status);
})
.catch((error) => {
    console.log(error);
});

실행


node app.js



[설정 화면에서 설정한 이름 + 알림] 형태로 알림이 옵니다.

간단한 알림에는 사용할 수 있습니다.

좋은 웹페이지 즐겨찾기