pdog18
V2EX  ›  问与答

咋让本地的 node 正常访问网络?

  •  
  •   pdog18 · Oct 16, 2021 · 1562 views
    This topic created in 1876 days ago, the information mentioned may be changed or developed.

    我有一个脚本需要请求外网 (请求网络通过 'node-fetch' 的 api )

    我的 terminal 是可以访问的,但是通过 node xx.js 运行脚本的时候好像无法访问。是需要对 node 进行某些设置吗?

    4 replies  •  2021-10-16 15:10:38 +08:00
    JKeita
    JKeita
    Oct 16, 2021❤️1
    1
    node 不清楚,反正 go http 相关包可以设置代理。
    pdog18
    pdog18
    OP
    Oct 16, 2021
    2
    我不太清楚这个 js 脚本里面的 node fetch API 从哪进行联网的,咋才可以把它走的那条网络让代理“覆盖”到,就像 termial 设置一下 https_proxy 之类的
    makelove
    makelove
    Oct 16, 2021❤️1
    3
    import HttpsProxyAgent from 'https-proxy-agent'
    const agent = proxy ? new HttpsProxyAgent(proxy) : undefined
    const res = await fetch(url, { agent })
    pdog18
    pdog18
    OP
    Oct 16, 2021
    4
    @makelove 感谢
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2204 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 03:11 · PVG 11:11 · LAX 19:11 · JFK 22:11
    ♥ Do have faith in what you're doing.