javascript - 如何获取node.js REPL中模块功能的帮助?

标签 javascript node.js npm

我正在尝试使用 REPL 获取属于 node.js 中模块的函数的一些文档,基本上是手册页。

Console.dir(modObj) 列出了属于某个模块的所有方法和属性。此外,我无法找到任何针对该函数的手册或帮助来演示该函数的示例和用法。

在 Python Interactive Shell 中同样非常简单,如下所示。查看模块的官方在线文档是一种替代方法。 REPL 是否对所有模块的手册页都有内置支持?

在 Python 交互式 Shell 中:-

import os
dir (os)
['EX_CANTCREAT', 'EX_CONFIG', 'EX_DATAERR', 'EX_IOERR', 'EX_NOHOST', 'EX_NOINPUT', 'EX_NOPERM', 'EX_NOUSER', 'EX_OK', 'EX_OSERR', 'EX_OSFILE', 'EX_PROTOCOL', 'urandom', 'utime', 'wait', 'wait3', 'wait4', 'waitpid', 'walk', 'write']
help(os.walk)
Help on function walk in module os:

walk(top, topdown=True, onerror=None, followlinks=False)
    Directory tree generator.

    For each directory in the directory tree rooted at top (including top
    itself, but excluding '.' and '..'), yields a 3-tuple

        dirpath, dirnames, filenames

    dirpath is a string, the path to the directory.  dirnames is a list of
    the names of the subdirectories in dirpath (excluding '.' and '..').
    filenames is a list of the names of the non-directory files in dirpath.
    Note that the names in the lists are just names, with no path components.
    To get a full path (which begins with top) to a file or directory in
    dirpath, do os.path.join(dirpath,name).

在 Node 的 REPL 中:-

> var fs=require('fs')
undefined
> console.dir(fs)
{ Stats: [Function],
  F_OK: 0,
  R_OK: 4,
  W_OK: 2,
  X_OK: 1,
  access: [Function],
  accessSync: [Function],
  exists: [Function],
  existsSync: [Function],
  readFile: [Function],
  readFileSync: [Function],
  close: [Function],
  closeSync: [Function],
  open: [Function],
  openSync: [Function],
  read: [Function],
  readSync: [Function],
  write: [Function],
  writeSync: [Function],
  rename: [Function],
  renameSync: [Function],
  truncate: [Function],
  truncateSync: [Function],
  ftruncate: [Function],
  ftruncateSync: [Function],
  rmdir: [Function],
  rmdirSync: [Function],
  fdatasync: [Function],
  fdatasyncSync: [Function],
  fsync: [Function],
  fsyncSync: [Function],
  mkdir: [Function],
  mkdirSync: [Function],
  readdir: [Function],
  readdirSync: [Function],
  fstat: [Function],
  lstat: [Function],
  stat: [Function],
  fstatSync: [Function],
  lstatSync: [Function],
  statSync: [Function],
  readlink: [Function],
  readlinkSync: [Function],
  symlink: [Function],
  symlinkSync: [Function],
  link: [Function],
  linkSync: [Function],
  unlink: [Function],
  unlinkSync: [Function],
  fchmod: [Function],
  fchmodSync: [Function],
  chmod: [Function],
  chmodSync: [Function],
  fchown: [Function],
  fchownSync: [Function],
  chown: [Function],
  chownSync: [Function],
  _toUnixTimestamp: [Function: toUnixTimestamp],
  utimes: [Function],
  utimesSync: [Function],
  futimes: [Function],
  futimesSync: [Function],
  writeFile: [Function],
  writeFileSync: [Function],
  appendFile: [Function],
  appendFileSync: [Function],
  watch: [Function],
  watchFile: [Function],
  unwatchFile: [Function],
  realpathSync: [Function: realpathSync],
  realpath: [Function: realpath],
  createReadStream: [Function],
  ReadStream:
   { [Function: ReadStream]
     super_:
      { [Function: Readable]
        ReadableState: [Function: ReadableState],
        super_: [Object],
        _fromList: [Function: fromList] } },
  FileReadStream:
   { [Function: ReadStream]
     super_:
      { [Function: Readable]
        ReadableState: [Function: ReadableState],
        super_: [Object],
        _fromList: [Function: fromList] } },
  createWriteStream: [Function],
  WriteStream:
   { [Function: WriteStream]
     super_: { [Function: Writable] WritableState: [Function: WritableState], super_: [Object] } },
  FileWriteStream:
   { [Function: WriteStream]
     super_: { [Function: Writable] WritableState: [Function: WritableState], super_: [Object] } } }
undefined
>
> help(fs.stat)
ReferenceError: help is not defined
    at repl:1:1
    at REPLServer.defaultEval (repl.js:252:27)
    at bound (domain.js:287:14)
    at REPLServer.runBound [as eval] (domain.js:300:12)
    at REPLServer.<anonymous> (repl.js:417:12)
    at emitOne (events.js:82:20)
    at REPLServer.emit (events.js:169:7)
    at REPLServer.Interface._onLine (readline.js:210:10)
    at REPLServer.Interface._line (readline.js:549:8)
    at REPLServer.Interface._ttyWrite (readline.js:826:14)

最佳答案

我认为 Node 目前还没有在 REPL 中提供它的文档。在node的官方仓库中针对同样的事情打开了一个问题,你可以查看here

npm 中有一个工具可以满足您的需求 node-help

但是,如果您对使文档离线感到满意,那么我可以推荐一些工具。

  • DevDocs - 它可用于将各种语言的文档直接保存到您的浏览器中。
  • ZealDocs - 如果您不习惯每次打开浏览器,那么这个实用程序可以帮助您。

关于javascript - 如何获取node.js REPL中模块功能的帮助?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52509743/

相关文章:

javascript - Node 更新特定包

javascript - 表格布局 : fixed css not working properly with given column's width

php - 如何摆脱下面 undefined index ?

javascript - 如何在 PHP 中点击按钮将数据插入数据库时​​增加进度条

javascript - 为什么我的表单多次 POSTING 并且 Socket 发出多个事件?

javascript - 使用 ember 生成插件命令

javascript - Parcel JS : tree. 渲染不是函数

javascript - 调整视频iframe的高度

javascript - 从 Sequelize getter 方法访问关联表

javascript - 如何在node.js中杀死child_process——req.on close