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.
- If you wanted to run the script without a
package.json you can use the node <filename.js> command
- 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
package.jsonfile inC:\Users\Joshu\OneDrive\Documents\Coding\jamming? If not, you should create apackage.json.C:\Users\Joshu\OneDrive\Documents\Coding\jamming?npm initnotnpm start.package.json