[ node js ]

   Á¶È¸ 3209   Ãßõ 0    

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


해NJ17; URL1012; 참1312;Ȣ16;여, 아래1032; js를 실행Ȣ16;였1004;나, 에러가 0156;생Ȣ16;네요
해NJ17; 문1244;1216; 해결1012; 위Ȣ16;여, 1312;Ǻ16; ǥ12;ᓠ1; 드/140; 봅니다.
감사합니다.

 

----- 실행 화면 (에러 0156;생)

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

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

Node.js v19.3.0

----- 1204;체 코드

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

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

// prepend http if it does not exist.
if (!/^https?:\/\//i.test(link)) {
&#160; &#160; 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){
&#160; &#160; if(!error && response.statusCode === 200 && body)
&#160; &#160; {
&#160; &#160; &#160; &#160; var json = JSON.parse(body);
&#160; &#160; &#160; &#160; console.log(json.data.url);
&#160; &#160; }
});

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

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


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


QnA
Á¦¸ñPage 15/439
2023-07   3265   ¼Ò¸®»ç¶û
2023-06   3257   ¾ß¾²¿À
2022-12   3250   °£Àå°ÔÀå
2023-09   3250   lico98
2022-12   3249   È­Á¤Å¥»ï
2022-08   3248   ¾¾¿£
2022-12   3246   ±è¹ÎöGC
2023-10   3238   ¸¶½ºÅÍÄ¡ÇÁ
2023-09   3236   ¼öÆÛ½ÎÀ̾ð
2023-08   3235   ÁÒ½´¾Æ
2023-03   3234   Å°¸£È÷È£ÇÁ
2023-04   3233   ¿ìÁÖ¼Ò³â
2022-10   3232   ³ª¿ì¸¶Å©
2023-11   3230   chotws
2023-05   3227   VSPress
2023-04   3227   ÀÌ»óÈÆLEE
2023-01   3222   ÀϹÝÀ¯Àú
2022-05   3218   ·¹³ª
2022-05   3217   ¸»¹ú
2022-07   3216   ÂÉÄ¿