[ node js ]

   Á¶È¸ 3275   Ãßõ 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 275/440
2023-03   1041   VSPress
2023-03   1475   À縶
2023-03   1955   Smoltz
2023-03   1713   ¹«½î»Ôó·³
2023-03   1514   ±èÁØÀ¯
2023-03   3082   ¹Ì´ã
2023-03   3897   slowcity
2023-03   1658   kyile
2023-03   1924   È­¶õ
2023-03   2429   ¼öÆÛ½ÎÀ̾ð
2023-03   2786   ±èµ¿ÀÚ¸Ç
2023-03   2351   ¯´Ô
2023-03   1597   2CPUÃÖÁÖÈñ
2023-03   1886   ¹«½î»Ôó·³
2023-03   2500   ·ù·ù·ù
2023-03   1830   Àü¼³¼ÓÀǹ̡¦
2023-03   1773   ¹üÀÌ´Ô
2023-03   2135   Çã¹Ö¹öµå
2023-03   1455   ¹Ì´ã
2023-03   1433   LevinF