the current running file in node?
My problem is that when im creating a database it's using the realtive the path from where npm start is run.
I have a backend/src/cache/cache.js
I want to create the db file from there.
Inside i have a const db_path = '../../db/cache.db'
But when i run npm start the db creation is using backend/../../db/cache.db relative to backend folder but the intended would be backend/src/cache/cache.js/../../db/cache.db
Got it: import path from 'path'; const currentDir = path.resolve(__dirname); const parentDir = path.dirname(currentDir); const DB_FILE_PATH = path.join(parentDir, '../../db/cache.db');
Обсуждают сегодня