[英]Nodejs, require module from within a function, or at top of script. Which is better for custom modules?
[英]How to require modules from another module - Nodejs
我有一个由2个文件组成的nodejs应用程序,index.js是主要的文件,能够路由其他所有内容,ping.js是使用phantomJS功能。 在我的index.js中,我有以下电话:
var phantomMy = require('./ping.js');
在ping.js中,我需要phantomJS-网页的标准模块,所以我有这样的调用
var page = require('webpage').create();
但这给我错误:
Error: Cannot find module 'webpage'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
..
我在做什么错-可能不仅是语法上的问题,还是架构上的问题?
网页模块是PhantomJS的模块。 如果使用node index.js
运行文件,则会出现该错误。 您需要将其作为phantomjs index.js
运行才能正常工作。 如果您尝试与phantomjs进行通信,建议您研究其他一些模块,例如phantomjs-node,而不要编写自己的模块。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.