1

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/.

6
  • What happens if you try readFileSync("../config.toml", 'utf-8'). It looks like the config.toml file is in the directory outside of database.js Commented Jun 18, 2022 at 5:34
  • @John It is strange, since in web3.js and index.js I have "./config.toml" and it has not given me any problem, although with "../config.toml" now the file runs fine starting it individually with node database but still does not start with npm start or node src/ Commented Jun 18, 2022 at 5:48
  • Do you import or reference databas.js inside index.js? Commented Jun 18, 2022 at 5:50
  • Maybe this answer is helpful? stackoverflow.com/a/50559862/1471485 Commented Jun 18, 2022 at 5:51
  • Try to add the watch flag. nodemon --watch src --ignore src/public/*. Docs: github.com/remy/nodemon#monitoring-multiple-directories Commented Jun 18, 2022 at 5:57

1 Answer 1

0

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/*"
}

Link to doc for reference

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.