[ node js ]

   Á¶È¸ 2863   Ãßõ 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/437
2023-05   2945   À嵿°Ç2014
2022-05   1069   pumkin
2023-05   1658   À̸ŸÁ·®2
2022-04   1773   °³³ä¸·¸·
2023-05   1099   ¹Î°æ¿­
2022-04   3043   YODA34
2023-05   1124   À̸ŸÁ·®2
2022-04   1842   soniit
2023-05   2288   Á¦·Î¿ø¼ÒÇÁÆ®
2022-04   1415   Ai20
2023-05   1069   ¹«½î»Ôó·³
2022-04   1282   ¹Ì¼ö¸Ç
2023-05   1120   tuffguy7
2022-04   1083   ÆäÆ®¸¯
2023-05   2501   ÁÒ½´¾Æ
2022-04   1389   ´ÏÁô
2023-05   1396   sbg2005
2022-04   3583   ÁÒ½´¾Æ
2023-05   899   ±è·ç³ë
2022-04   10858   Ç®·Îµå½Ã½ºÅÛ