Node.js requireと.load

REPLにスクリプトを読み込む

引き続き1章を読み進めている。REPL に自作のスクリプトやnpmのパッケージを読み込む方法が紹介されていた。

const hoge = require('./hoge')

require を使うんですね。知らなかった。わかってしまえば Node だから当然か!私は、今まで .load を使っていた。

> .help
.break    Sometimes you get stuck, this gets you out
.clear    Alias for .break
.editor   Enter editor mode
.exit     Exit the REPL
.help     Print this help message
.load     Load JS from a file into the REPL session
.save     Save all evaluated commands in this REPL session to a file

requireと.loadの違い

require.loadの違いを推測でまとめておく。

requireNode.js の命令で、 .loadREPLE の命令と理解した。require は 読み込んだスクリプトREPL** 環境を汚染するため、 delete でキャッシュをクリアできる。

間違っていれば、教えてください。