我目前正在用Node-RED开发一个应用程序,我想使用NPM的一些模块。有一个来自James的模块,它自动化了我可以使用的NPM模块(节点-红色-控制-npm)的实现。
不过,我希望首先对node.js进行更全面的手动实现,并更好地理解它的工作原理(我对node.js还不熟悉)。所以,我没有使用这个模块,而是作为官方的节点-红色指南,这里说。
functionGlobalContext: {
// os:require('os'),
// octalbonescript:require('octalbonescript'),
// jfive:require("johnny-five"),
// j5board:require("johnny-five").Board({repl:false})
// fileExists:require("file-exists") //DOESN'T WORK!!
ccount:require('ccount') //WORKS FINE!!
},
var ccount = context.global.get('ccount');
msg.a = ccount('((())))))', '(') //=> 2
msg.b = ccount('pepe', ')') //=> 1
return msg;
functionGlobalContext: {
// os:require('os'),
// octalbonescript:require('octalbonescript'),
// jfive:require("johnny-five"),
// j5board:require("johnny-five").Board({repl:false})
fileExists:require("file-exists") //DOESN'T WORK!!
// ccount:require('ccount') //WORKS FINE!!
},
fileExists('/media/pi/SMOOTHIE/firmware.cur', (err, exists) => console.log(exists)) // OUTPUTS: true or false
console.log(fileExists.sync('/media/pi/SMOOTHIE/firmware.cur')) // OUTPUTS: true or false
return msg;
当我执行节点红色启动时,控制台的输出是:
pi@raspberrypi:~ $ node-red-start
Start Node-RED
Once Node-RED has started, point a browser at http://192.168.1.104:1880
On Pi Node-RED works better with the Firefox or Chrome browser
Use node-red-stop to stop Node-RED
Use node-red-start to start Node-RED again
Use node-red-log to view the recent log output
Use sudo systemctl enable nodered.service to autostart Node-RED at every boot
Use sudo systemctl disable nodered.service to disable autostart on boot
Starting as a systemd service.
Started Node-RED graphical event wiring tool..
Error loading settings file: /home/pi/.node-red/settings.js
[SyntaxError: Unexpected token =]节点-红色日志输出如下:
13 Sep 19:29:20 - [info] Starting flows
13 Sep 19:29:20 - [info] Started flows
13 Sep 19:29:20 - [info] serial port /dev/ttyACM0 opened at 57600 baud 8N1
13 Sep 19:30:25 - [info] Stopping flows
13 Sep 19:30:25 - [info] serial port /dev/ttyACM0 closed
13 Sep 19:30:25 - [info] Stopped flows
13 Sep 19:30:25 - [info] Starting flows
13 Sep 19:30:25 - [info] Started flows
13 Sep 19:30:25 - [info] serial port /dev/ttyACM0 opened at 57600 baud 8N1
Stopping Node-RED graphical event wiring tool....
13 Sep 19:31:54 - [info] Stopping flows
Stopped Node-RED graphical event wiring tool..
Started Node-RED graphical event wiring tool..
Error loading settings file: /home/pi/.node-red/settings.js
[SyntaxError: Unexpected token =]
Started Node-RED graphical event wiring tool..
Started Node-RED graphical event wiring tool..
Error loading settings file: /home/pi/.node-red/settings.js
[SyntaxError: Unexpected token =]
Started Node-RED graphical event wiring tool..
Error loading settings file: /home/pi/.node-red/settings.js
[SyntaxError: Unexpected token =]
Started Node-RED graphical event wiring tool..
Error loading settings file: /home/pi/.node-red/settings.js
[SyntaxError: Unexpected token =]我没别的事要查了。这个过程很好,因为它适用于另一个npm节点。文件存在模块(https://www.npmjs.com/package/file-exists)是由麻省理工学院的一些人制作和维护的,每天下载大约80000次,所以我认为它应该能工作。在这个时候,GitHub回购没有提到任何其他问题。我做错什么了?
谢谢。
编辑:节点-e的输出“要求”(‘./EDIT ings.js’);
pi@raspberrypi:~/.node-red $ node -e "require('./settings.js');"
/home/pi/.node-red/node_modules/file-exists/index.js:4
function fileExists (filepath, options, done = function () {}) {
^
SyntaxError: Unexpected token =
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:373:25)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (/home/pi/.node-red/settings.js:179:13)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
pi@raspberrypi:~/.node-red $ 发布于 2017-09-13 21:13:52
文件存在节点所需的Nodev6.x或更高版本,错误是因为它使用的是节点v4.8.x不理解的新语法。
您可以使用这里中的Node-RED升级脚本,这将将Node-RED升级到最新版本,并将NodeJS升级到最新的v6构建。
https://stackoverflow.com/questions/46199939
复制相似问题