[ node js ]

   Á¶È¸ 3359   Ãßõ 0    

https://gist.github.com/jxson/963339/33a0623a000334aa0ab97def069c3902a1212f6c


해당 URL을 참조하여, 아래의 js를 실행하였으나, 에러가 발생하네요
해당 문젬점 해결을 위하여, 조언 부탁 드려 봅니다.
감사합니다.

 

----- 실행 화면 (에러 발생)

❯ bitly http://www.naver.com
/opt/homebrew/bin/bitly.js:3
        link = process.ARGV[2],
                           ^ # <======================================== !!!

TypeError: Cannot read properties of undefined (reading '2')
    at Object.<anonymous> (/opt/homebrew/bin/bitly.js:3:22)
    at Module._compile (node:internal/modules/cjs/loader:1218:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1272:10)
    at Module.load (node:internal/modules/cjs/loader:1081:32)
    at Module._load (node:internal/modules/cjs/loader:922:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:82:12)
    at node:internal/main/run_main_module:23:47

Node.js v19.3.0

----- 전체 코드

❯ \cat /opt/homebrew/bin/bitly.js
var request = require('request'),
        sys = require('sys'),
        link = process.ARGV[2],
        bitly = 'http://api.bit.ly/v3/shorten';

function urlencode(str) {
return escape(str)
    .replace('+', '%2B')
    .replace('%20', '+')
    .replace('*', '%2A')
    .replace('/', '%2F').replace('@', '%40');
}

// prepend http if it does not exist.
if (!/^https?:\/\//i.test(link)) {
    link = 'http://' + link;
}

// urlencode the link and add to params.
var params = 'login=YOUR_LOGIN_ID&apiKey=YOUR_API_KEY&longUrl='+urlencode(link)+'%2F&format=json';

request({uri:bitly, body:params, method:'POST'},function(error,response,body){
    if(!error && response.statusCode === 200 && body)
    {
        var json = JSON.parse(body);
        console.log(json.data.url);
    }
});

ªÀº±Û Àϼö·Ï ½ÅÁßÇÏ°Ô.
±èÁ¦¿¬ 2023-02
¼Ò¹®ÀÚ ÀÔ´Ï´Ù ARGV -> argv
Á¶¾ð °¨»çÇÕ´Ï´Ù.

¾Ë·Á ÁֽŠÁ¶Ä¡´ë·Î ÇÏ¿© ±âÁ¸ÀÇ ¹®Á¦Á¡Àº ¹ß»ýÇÏÁö ¾ÊÀ¸³ª,
  ÀǵµÇÑ °á°ú °ªÀÌ ¾Æ´Ñ ´Ù¸¥ °ªÀÌ Ãâ·ÂÀÌ µÇ¼­¿ä
❯ bitly www.google.com

❯ undefined # <======== cltr + v


¸Þ¸ðÀå¿¡ clipboard¿¡ ÀúÀåµÈ °á°ú °ªÀ» º¹»ç¸¦ Çغ¸¸é,
undefined
ÀÌ·± °ªÀ» Âï°í ÀÖ±â´Â ÇÕ´Ï´Ù. ²Ù¹÷ ~.~


QnA
Á¦¸ñPage 4464/5686
2014-05   4976310   Á¤ÀºÁØ1
2015-12   1512453   ¹é¸Þ°¡
2020-02   3360   ĵÀ§µå
2017-05   3360   ¿­¾¾¹Ì
2020-08   3360   ¾ÈöÇö
2023-02   3360   Àü¼³¼ÓÀǹ̡¦
2019-11   3360   ·ÎÇÇ
2018-10   3360   Nikon
2016-02   3360   Ãֽÿµ
2020-04   3360   »ßµ¹À̽½ÇÄÀÌ
2015-02   3360   Ǫ¸£¸ª
2017-04   3360   Æ丣¼¼¿ì½º
2014-12   3360   ³ªÆÄÀÌ°­½ÂÈÆ
2020-06   3359   ÀÌÁöÆ÷Åä
2018-08   3359   ³Ä¾Æ¾Æ¾Æ¾Ï
2022-03   3359   Àü¼³¼ÓÀǹ̡¦
2015-09   3359   °Ü¿ï³ª¹«
2020-06   3359   º¹ÁÖ¸Ó´Ï
2019-01   3359   ¼­¹öÀü¹®°¡¡¦
2015-02   3359   Á¶º´Ã¶
2016-09   3359   Psychophysi¡¦
2018-06   3359   °í¼ö´åÄÄ