[ node js ]

   Á¶È¸ 2880   Ãßõ 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/437
03-25   752   ¹«½î»Ôó·³
2023-02   1601   Zer0
03-22   654   ÇåÅÍD
2023-02   924   ³ëÀçÇö
03-21   999   EnBay
2023-02   1545   ½Öcpu
2023-02   16185   ¾ÈöÇö
03-19   732   ´ÙÀâ¾Æ
2023-02   1221   ½ÅÀº¿Ö
03-17   563   ¼­¿ï»ç¶÷
2023-02   1434   ½ÅÀº¿Ö
03-15   874   ±èµ¿Çõ1
2023-02   838   ¾ÆÄí
03-13   700   ¿Ã´Ð½º
2023-02   1070   Á¤ÀǼ®
03-12   877   Á¤¹«Çö
2023-02   1020   winner712
03-10   1348   ±¸¹ð
2023-02   2174   ½ÅÀº¿Ö
03-08   1029   chotws