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/
.
CodePudding user response:
EDIT:
From the comments, it looks like you figured it out by importing (require) all your files in index.js
. I have a feeling that your package.json file has a field main
, and it is set to src/index.js
.
It's difficult to understand what you are having trouble with.
I'm assuming you want to watch for changes in all of your JavaScript files inside the src
folder.
You could try to add the watch
flag to your command
inside package.json.
"scripts": {
"start": "nodemon --watch src --ignore src/public/*"
}