1

First time poster, thanks in advance for the help!

I'm trying to complete my first project and am running into a few issues. The main one being that when I hit npm start I get hit with this error message -

https://i.sstatic.net/gZXjV.png

I've tried hitting npm install before I run it but to no avail. Does anyone have any ideas?!

Thanks!

enter image description here

6
  • 3
    Did you make a package.json file in C:\Users\Joshu\OneDrive\Documents\Coding\jamming? If not, you should create a package.json. Commented Dec 24, 2019 at 3:40
  • What @Yousername said, Can you update your question to show the folder structure of C:\Users\Joshu\OneDrive\Documents\Coding\jamming? Commented Dec 24, 2019 at 3:44
  • i believe the command you should input when you first start up a project is npm init not npm start. Commented Dec 24, 2019 at 3:46
  • hey @AleksandarMisich, I've added additonal images in the post to show the new error i'm getting after I did npm init / npm start and pictures showing the folder structure. Thanks again for your help! Commented Dec 24, 2019 at 4:06
  • can you post the content of you package.json Commented Dec 24, 2019 at 5:39

1 Answer 1

2

Without the contents of the package.json I can only guess... As some of the comments have pointed our as well, make sure your node or npm command can navigate to/see your script file


Context:

But there are 2 concepts here. node & npm

1. Node is a runtime:

In order to run a node script you'll need the node command (within the context of the project your working on, so make sure your cli is in the root of your project) like this:

node ./folder/to/your-script.js

2. NPM is a package manager.

...and it relies on having a package.json in the same directory as where you're running the npm command for most of it's commands other than init (which creates the package.json file for you)


Problem:

The second screenshot is the clue here.

You tried running npm start, where the error message is:

missing script: start

This means that your scripts block does not contain a start property

Thus it seems to me as if you are mixing the 2 concepts.

  1. If you wanted to run the script without a package.json you can use the node <filename.js> command
  2. If you have dependencies, and want to make your life a little more convenient if you have a lot of other commands and dependencies, you can use the npm run <script> command.

(Side-note: npm start is a special case that seems to be able to run or without the run keyword, which I didn't know as well until I just tested it now :P)


Solution:

Therefor to get closer to what your expecting, we can modify the package.json as per below:

You can also create custom aliases for commands within the scripts block (inside the package.json):

 "scripts": {
   "start": "node ./some-path/to/your-script.js"
   "bar": "npm run foo",
   "foo": "node ./folder/to/your-script.js"
 }

You'll notice, you can reference sibling script aliases in other script commands as well (you can also add non node commands in here, like git, etc..)

Thus with the above in your package.json you'll have access to the following commands when running npm in the same directory as the package.json.

npm start, npm run foo or npm run bar

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.