1

this is my package.json file:

{
  "name": "martina",
  "version": "1.0.0",
  "description": "d",
  "main": "index.js",
  "scripts": {
    "start": "node index.js",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "repository": {
    "type": "git",
    "url": "d"
  },
  "author": "",
  "license": "ISC"
}

what should I do? I have a Mac by the way!

EDIT: I did what you guys recommended and added the script start, but now when I run 'npm start' I get this:

> martina@1.0.0 start /Users/martina
> node index.js

internal/modules/cjs/loader.js:589
    throw err;
    ^

Error: Cannot find module '/Users/martina/index.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:587:15)
    at Function.Module._load (internal/modules/cjs/loader.js:513:25)
    at Function.Module.runMain (internal/modules/cjs/loader.js:760:12)
    at startup (internal/bootstrap/node.js:303:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:872:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! martina@1.0.0 start: `node index.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the martina@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/martina/.npm/_logs/2020-06-11T08_05_28_654Z-debug.log
Martina
  • 35
  • 1
  • 5
  • Duplicate: https://stackoverflow.com/q/31976722/1233251 – E_net4 Jun 10 '20 at 22:01
  • I believe `start` needs to be in the `"scripts"` section of package.json; right now you only have `test` as a script. I would look into how to include an actual start script. – Matthew P. Jun 10 '20 at 22:02
  • Does this answer your question? [Start script missing error when running npm start](https://stackoverflow.com/questions/31976722/start-script-missing-error-when-running-npm-start) – Lewis Jun 10 '20 at 22:30
  • @Martina, have a look at the PS of my answer. – Deepak Tatyaji Ahire Jun 11 '20 at 09:11

3 Answers3

1

You need to add a start script under scripts, i.e.:

{
  "name": "martina",
  "version": "1.0.0",
  "description": "d",
  "main": "index.js",
  "scripts": {
    "start": "echo STARTING...",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "repository": {
    "type": "git",
    "url": "d"
  },
  "author": "",
  "license": "ISC"
}

Try npm run test to get an idea of how the scripts field works for package.json.

Lewis
  • 4,285
  • 1
  • 23
  • 36
1

You need to add a start script under scripts, and to host or start the application on local node server, add the command node index.js as the value for start script.

{
  "name": "martina",
  "version": "1.0.0",
  "description": "d",
  "main": "index.js",
  "scripts": {
    "start": "node index.js",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "repository": {
    "type": "git",
    "url": "d"
  },
  "author": "",
  "license": "ISC"
}

PS: While running the command npm start, make sure that you are in the correct project directory. The file index.js and package.json needs to be present as the direct childs of this project directory.

Project Structure:

martina
  |- index.js
  |- package.json
  |- file1
  |- file2
  |- ...other files
  ...

See in the above project structure, martina is the main project directory. And inside martina, index.js and package.json can be found.

Deepak Tatyaji Ahire
  • 4,883
  • 2
  • 13
  • 35
-1
{
  "name": "martina",
  "version": "1.0.0",
  "description": "d",
  "main": "index.js",
  "scripts": {
    "start": "node index.js",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "repository": {
    "type": "git",
    "url": "d"
  },
  "author": "",
  "license": "ISC"
}

Your package appears by looking at the file. That you have just created the project. It seems that the directory of your index.js file in not correct. you create the index.js file in the package.json directory itself, after that run the node index.js or npm start command

> martina@1.0.0 start /Users/martina
> node index.js

internal/modules/cjs/loader.js:589
    throw err;
    ^

Error: Cannot find module '/Users/martina/index.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:587:15)
    at Function.Module._load (internal/modules/cjs/loader.js:513:25)
    at Function.Module.runMain (internal/modules/cjs/loader.js:760:12)
    at startup (internal/bootstrap/node.js:303:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:872:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! martina@1.0.0 start: `node index.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the martina@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/martina/.npm/_logs/2020-06-11T08_05_28_654Z-debug.log

Try this one. Your solution will be done. If you still get an error then let me know

satendra singh
  • 129
  • 1
  • 11