在Node Repl中使用.load函数的问题
我正在运行Nodejs并尝试使用以下命令在repl中加载脚本:.load transformscript.js
transformscript.js中的前两行如下:.load rdfMapping.js
.load rdfVocab.js
问题是我收到错误'SyntaxError:Unexpected token'。在第一行。有人知道为什么会这样,因为我对Node和repl没有多少经验。
回答如下:您只能在REPL控制台中使用.load path_to_the_module
命令。要在文件脚本中加载模块,您需要使用require('path_to_the_module')
。
所以transformscript.js
的第一行应该是:
require('./rdfMapping.js');
require('./rdfVocab.js');