Well, the problem is simple to explain and although I have investigated I have not found a solution
When I start the project in src/ with either nodemon src/ --ignore src/public/*(with the npm start script) or node src/ commands only two .js files are executed in src/ and these are web3.js and index.js, nodemon and node completely ignore the existence of database.js
I thought that the error might be in the code in database.js so I created the file test.js which makes a simple console.log to check if it was executed but not
The files are structured as follows:
src/
- database.js
- index.js
- test.js
- web3.js
package.json
config.toml
I tried to run the database.js file independently with node and got this error, which is weird because in web3.js and index.js I also get the toml file the same way.
> node src/database.js
node:internal/fs/utils:345
throw err;
^
Error: ENOENT: no such file or directory, open './config.toml'
The code that gives this error, although irrelevant, here it is
const { readFileSync } = require("fs");
const { mongoUriOp } = toml.parse(readFileSync("./config.toml", 'utf-8'));
I tried (thanks to a comment) changing the config path to "../config.toml" and the file ran with node database, but it still won't run with npm start or node src/.
readFileSync("../config.toml", 'utf-8'). It looks like theconfig.tomlfile is in the directory outside ofdatabase.js"./config.toml"and it has not given me any problem, although with"../config.toml"now the file runs fine starting it individually withnode databasebut still does not start withnpm startornode src/databas.jsinsideindex.js?watchflag.nodemon --watch src --ignore src/public/*. Docs: github.com/remy/nodemon#monitoring-multiple-directories