如何REPL快速javascript测试

时间:2014-01-28 08:44:39

标签: windows node.js module

我刚开始使用node.js.我已经构建了一个模块,我试图在REPL中快速运行它。

在我的模块中,我有这个(不包括这里的胆量)

var templateModule = (function (templateModule) {

     //implimentation...

     // return module
     return templateModule;
})(templateModule || {});

 // do the export so node is happy
 module.exports.templateModule = templateModule;

也许我错过了一些明显的东西。在 windows I CD到c:/ nodeCode /并运行节点。 然后在node-REPL I中输入

  

var temp = require('templateModule');

结果:

 Error: Cannot find module 'templateModule'
       at Function.Module._resolveFilename ...

如果我执行包含require的节点test-server.js,我也会收到此错误。

也许我错过了一些样板?也许我需要一个package.json或者什么?该文档令人困惑,我无法找到一个好的REPL node.js hello world示例for windows。

更新:

似乎我可以使用browserify在浏览器中正常使用模块......我的路径或节点安装可能会破坏某些内容吗?

1 个答案:

答案 0 :(得分:0)

由于它是一个自定义模块,你必须这样做:

var temp = require('./templateModule'); 

或:

var temp = require('./templateModule.js');

,假设您的模块文件名为“templateModule.js”,并且您正在运行de node命令的同一目录中。

This article可能会对您有所帮助。

相关问题