Exact list of Node core modules

后端 未结 5 2065
一个人的身影
一个人的身影 2021-02-04 05:56

I am looking for a way to get an exact up-to-date list of all Node.js core modules. Is there an NPM module that supplies such a running list? Somewhere in the annals of my life

5条回答
  •  暖寄归人
    2021-02-04 06:24

    J4F: you can use the github api and get a list of files directly in JSON format.

    var http = require('https')
    var path = require('path')
    
    var options = {
      hostname: 'api.github.com',
      path: '/repos/nodejs/node/contents/lib',
      method: 'GET',
      headers: { 'Content-Type': 'application/json', 
                 'user-agent': 'nodejs/node' 
      }
    }
    
    var req = http.request(options, (res) => {
      res.setEncoding('utf8')
      var body = ""
      res.on('data', (data) => { body += data })
      res.on('end', () => {
        var list = []
        body = JSON.parse(body)
        body.forEach( (f) => {
          if (f.type === 'file' && f.name[0]!=='_' && f.name[0]!=='.') {
            list.push(path.basename(f.name,'.js'))
          }
        })
        console.log(list)
      })
    })
    req.on('error', (e) => { throw (e) } )
    req.end()
    

提交回复
热议问题