Michael Alves
Michael Alves

Reputation: 635

Node cannot find the start module

I am trying to set-up a very simple test with node. To do so, I have created the following package.json:

{
  "dependencies": {
    "express": "*"
  },
  "scripts": {
    "start": "node index.js"
  },
  "name": "course-43",
  "version": "1.0.0",
  "description": "Simple test",
  "main": "index.js",
  "devDependencies": {},
  "author": "",
  "license": "ISC"
}

Then I have installed the dependencies with "npm install" and I have executed the "node start" command which outputs the following error:

$ node start
internal/modules/cjs/loader.js:800
    throw err;
    ^

Error: Cannot find module 'C:\[...]\Course-43\start'
?[90m    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:797:15)?[39m
?[90m    at Function.Module._load (internal/modules/cjs/loader.js:690:27)?[39m
?[90m    at Function.Module.runMain (internal/modules/cjs/loader.js:1047:10)?[39m
?[90m    at internal/main/run_main_module.js:17:11?[39m {
  code: ?[32m'MODULE_NOT_FOUND'?[39m,
  requireStack: []
}

The node start command is executed in the same directory as my package.json file.

Can someone help me to understand why node.js is trying to load a file instead of the script in my package.json file ?

Upvotes: 0

Views: 300

Answers (1)

Sebastian Kaczmarek
Sebastian Kaczmarek

Reputation: 8515

You have to run npm start instead of node start. If you want to use node directly, then you should use node index.js. But the npm start option will do the same in this case

Upvotes: 1

Related Questions