in my environment,i import project ,nodejs directory has node.exe,data directory has two db documents(temp.db、test.db) , i config node find "./data/temp.db" can execute,but test.db appears error failed to open "./data/test.db",so i change config "../data/test.db" is working;
in others environment ../data/test.db、./testdb both not working
absolute directory is working,how to debug
You may need to post part of your settings.js
file which shows what paths are shared.
console.log('Loading settings from:', __dirname);
process.env.PATH = `${process.env.PATH};`+__dirname+'\\lib';
process.env.PATH = `${process.env.PATH};`+__dirname+'\\lib\\ias';
console.log('process env PATH:',process.env.PATH);
const newPath = __dirname;
try {
process.chdir(newPath);
} catch (err) {
console.error('修改工作路径失败:', err.message);
}
module.exports = {
flowFile: 'flows.json',
flowFilePretty: true,
userDir: __dirname + '/data',
nodesDir: __dirname +'/nodes',
uiPort: process.env.PORT || 1880,
httpAdminRoot: '/admin',
httpStatic:__dirname + '/data/static',
lang: "zh-CN",
diagnostics: {
enabled: true,
ui: true,
},
runtimeState: {
enabled: false,
ui: false,
},
logging: {
console: {
level: "debug",
metrics: false,
audit: false
},
file: {
level: "debug",
filename: "./node-red.log",
metrics: true,
audit: true,
maxFiles: 5, // 保留的日志文件数
maxsize: 10485760 // 单个日志文件大小(10MB)
}
},
exportGlobalContextKeys: false,
externalModules: {
},
disableEditor: false,
editorTheme: {
palette: {
},
projects: {
enabled: false,
workflow: {
/** Set the default projects workflow mode.
* - manual - you must manually commit changes
* - auto - changes are automatically committed
* This can be overridden per-user from the 'Git config'
* section of 'User Settings' within the editor
*/
mode: "manual"
}
},
codeEditor: {
lib: "monaco",
options: {
}
},
markdownEditor: {
mermaid: {
enabled: true
}
},
multiplayer: {
enabled: false
},
},
functionExternalModules: true,
functionTimeout: 0,
debugMaxLength: 1000,
mqttReconnectTime: 15000,
serialReconnectTime: 15000,
functionGlobalContext: {
//设备IP地址
http: require('http'),
fs: require('fs'),
exeDir: __dirname
}
}
setting.js file as above
Oh, sorry, some other details:
O/S being used
NR version
windows
NR Version 4.0.9
package json
{
"name": "server",
"version": "4.0.9",
"description": "Low-code programming for event-driven applications",
"homepage": "https://nodered.org",
"license": "Apache-2.0",
"bin": "packages/node_modules/node-red/red.js",
"repository": {
"type": "git",
"url": "https://github.com/node-red/node-red.git"
},
"private": "true",
"scripts": {
"start": "node packages/node_modules/node-red/red.js --settings ./settings.js",
"test": "grunt",
"build": "grunt build",
"dev": "grunt dev",
"build-dev": "grunt build-dev",
"docs": "grunt docs",
"pkg": "pkg . --out-path dist",
"nexe-build": "nexe packages/node_modules/node-red/red.js -o server.exe --build",
"package": "electron-packager . --platform=win64 --arch=x64"
},
"pkg": {
"scripts": "packages/node_modules/node-red/red.js",
"assets": [
"settings.js",
"node_modules/**/*",
"packages/node_modules/**/*"
],
"targets": [
"node18-win-x64"
]
},
"contributors": [
{
"name": "Nick O'Leary"
},
{
"name": "Dave Conway-Jones"
}
],
"dependencies": {
"acorn": "8.12.1",
"acorn-walk": "8.3.4",
"ajv": "8.17.1",
"async-mutex": "0.5.0",
"basic-auth": "2.0.1",
"bcryptjs": "2.4.3",
"body-parser": "1.20.3",
"cheerio": "1.0.0-rc.10",
"clone": "2.1.2",
"content-type": "1.0.5",
"cookie": "0.7.2",
"cookie-parser": "1.4.7",
"cors": "2.8.5",
"cronosjs": "1.7.1",
"denque": "2.1.0",
"express": "4.21.2",
"express-session": "1.18.1",
"ffi-napi": "4.0.3",
"form-data": "4.0.0",
"fs-extra": "11.2.0",
"got": "12.6.1",
"hash-sum": "2.0.0",
"hpagent": "1.2.0",
"https-proxy-agent": "5.0.1",
"i18next": "21.10.0",
"iconv-lite": "0.6.3",
"is-utf8": "0.2.1",
"js-yaml": "4.1.0",
"json-stringify-safe": "5.0.1",
"jsonata": "2.0.5",
"lodash.clonedeep": "^4.5.0",
"media-typer": "1.1.0",
"memorystore": "1.6.7",
"mime": "3.0.0",
"moment": "2.30.1",
"moment-timezone": "0.5.46",
"mqtt": "5.7.0",
"multer": "1.4.5-lts.1",
"mustache": "4.2.0",
"node-red-admin": "^4.0.1",
"node-red-contrib-ui-etable": "^4.6.3",
"node-red-contrib-zip": "~1.1.0",
"node-red-dashboard": "^3.6.5",
"node-red-node-sqlite": "^1.1.0",
"node-watch": "0.7.4",
"nopt": "5.0.0",
"oauth2orize": "1.12.0",
"on-headers": "1.0.2",
"passport": "0.7.0",
"passport-http-bearer": "1.0.1",
"passport-oauth2-client-password": "0.1.2",
"raw-body": "3.0.0",
"ref-array-di": "^1.2.2",
"ref-array-napi": "1.2.2",
"ref-napi": "3.0.3",
"ref-struct-napi": "1.1.1",
"rfdc": "^1.3.1",
"semver": "7.6.3",
"tar": "7.4.3",
"tough-cookie": "^5.0.0",
"uglify-js": "3.17.4",
"uuid": "9.0.1",
"ws": "7.5.10",
"xml2js": "0.6.2"
},
"optionalDependencies": {
"@node-rs/bcrypt": "1.10.4"
},
"devDependencies": {
"dompurify": "2.5.7",
"grunt": "1.6.1",
"grunt-chmod": "~1.1.1",
"grunt-cli": "~1.5.0",
"grunt-concurrent": "3.0.0",
"grunt-contrib-clean": "2.0.1",
"grunt-contrib-compress": "2.0.0",
"grunt-contrib-concat": "2.1.0",
"grunt-contrib-copy": "1.0.0",
"grunt-contrib-jshint": "3.2.0",
"grunt-contrib-uglify": "5.2.2",
"grunt-contrib-watch": "1.1.0",
"grunt-jsdoc": "2.4.1",
"grunt-jsdoc-to-markdown": "6.0.0",
"grunt-jsonlint": "3.0.0",
"grunt-mkdir": "~1.1.0",
"grunt-npm-command": "~0.1.2",
"grunt-sass": "~3.1.0",
"grunt-simple-mocha": "~0.4.1",
"grunt-simple-nyc": "^3.0.1",
"i18next-http-backend": "1.4.1",
"jquery-i18next": "1.2.1",
"jsdoc-nr-template": "github:node-red/jsdoc-nr-template",
"marked": "4.3.0",
"mermaid": "11.3.0",
"minami": "1.2.3",
"mocha": "9.2.2",
"node-red-node-test-helper": "^0.3.3",
"nodemon": "3.1.7",
"proxy": "^1.0.2",
"sass": "1.62.1",
"should": "13.2.3",
"sinon": "11.1.2",
"stoppable": "^1.1.0",
"supertest": "6.3.3"
},
"engines": {
"node": ">=18.5"
}
}
Ah, windoze.......
Not my area. I'd better step back and let others help you.
None of this is really necessary.
Since data
is relative to the settings.js, you should be able to specify a relative path data/test.db
in the SQL node.
data/tes.db also fail to open
if that is what you entered, then there is no surprise.
if you really entered data/test.db
then something else is amiss.
did you remove your extra code in settings.js process.chdir(newPath);
and restart node-red?.
If you add a simple flow inject -> exec -> debug
and put cd
in the command, what do you get when inject is operated?
remove process.chdir(newPath); restart still 16:52:45 - [error] [sqlitedb:5e9b1c6f4b6bad59] failed to open data/test.db
test.db can use tool access,test.db and temp.db is same;
You say:
Then you say:
so I cannot really understand what you are saying.
Maybe you have a lock on the database. try closing any database management applications. try restarting the computer.
also, check you have not got more than one db config node configured for the same database (you have 2 database files, there should only be 2 configs in the dropdown)
try restart computer already,2 db config,debug like this,only ../data can access,data/和./data not,but temp.db can access by ./data/temp.db
I'm sorry but you are changing things and only reporting small parts of info making it very difficult to help.
- show me the files in
data
dir - show me the output of
cd
using the flow I suggested above - show me the settings in the 2 configs.
- 1 should have
data/test.db
- 2 should have
data/temp.db
- 1 should have
2 not understand
Do this ↓
THERE SHOULD BE 2 CONFIGS for 2 DATABASE CONNECTIONS
Select 1st one then click edit
Select 2nd one then click edit
after 6 hours i can reply,because i am first ,offical is limit