【发布时间】:2017-06-19 10:02:04
【问题描述】:
我正在开发 Node JS 应用程序。
在此我必须检查第一个用户是否已连接到互联网。如果是,请检查KinectRuntime-v2.0_1409-Setup 是否安装.. 还有更多此类验证。所以我在我的入口脚本中使用了以下代码:
我做了什么:
broadcast.js: // 我们用来启动应用程序的入口文件
var tempkinect = require('./controllers/tempkinect.js');
tempkinect.controller(app);
require('dns').lookup('google.com',function(err) {
if (err){
server.listen(8000, function(req, res){
open('http://localhost:8000/internetnotfound'); // internet not found page.
return false;
});
}
else{
try{
var Kinect2 = require("kinect2");
var kinect = new Kinect2();
}
catch(ex) {
server.listen(8000, function(req, res){
open('http://localhost:8000/kinectnotfound');
open('https://www.microsoft.com/en-in/download/confirmation.aspx?id=44559');
return false;
}
} //else ends here
});
tempkinect.js 文件://我的控制器文件
module.exports.controller = function(app){
app.get('/kinectnotfound',function(req,res){
var errmsg = "KinectRuntime-v2.0_1409-Setup not installed on your computer. Download will start automatically, if not then";
var link = "https://www.microsoft.com/en-in/download/confirmation.aspx?id=44559";
var click = "Click Here!"
res.render('initialerror',{errormessage:errmsg, downloadlink : link, clickhere: click, title : 'Kinect Not Found'});
});
app.get('/internetnotfound', function(req,res){
require('dns').lookup('google.com',function(err) {
if (err){
res.render('initialerror',{errormessage:'Please Connect Internet for Login.',downloadlink : '', clickhere : '', title : 'Internet Not Connected'});
}
else{
res.redirect('/restart');
}
});
});
app.get('/restart', function (req, res, next) {
process.exit(1);
});
}
我正在使用 enclose 模块,它编译了节点 js 应用程序并创建了 .exe 文件。现在,如果我使用命令提示符在本地机器上运行应用程序:
运行>节点广播.js
然后在找不到互联网的情况下,应用程序会显示相应的页面。(然后我手动连接互联网)在连接互联网后,当我刷新页面时它会重新启动该过程,这符合要求。
但是,当我使用已编译的应用程序执行相同操作时,它会给我错误:
我遇到了什么错误:
除此之外,Forever 应该作为全局安装在系统上,这样它就可以在我的系统上正常运行,但不能在其他使用已编译应用程序的系统上运行。
【问题讨论】:
-
您的错误链接已损坏。
标签: node.js node-modules forever enclose