Reputation: 189
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 -
I've tried hitting npm install before I run it but to no avail. Does anyone have any ideas?!
Thanks!
Upvotes: 1
Views: 1126
Reputation: 5403
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
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)
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.
package.json
you can use the node <filename.js>
command 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)
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
Upvotes: 2