Jeanluca Scaljeri
Jeanluca Scaljeri

Reputation: 29199

npm: create script command

When I run my NodeJs (ES6) project I type in the console the following:

./node_modules/babel/bin/babel-node.js index.js

Now I would like to add this command to the script section of package.json. So I did:

"scripts": {
    "run": "./node_modules/babel/bin/babel-node.js index.js"
},

Now when I run this I get:

$> npm run
Lifecycle scripts included in App:

run
   ./node_modules/babel/bin/babel-node.js index.js

And it doesn't run anything!

Why can't I do this? For example, if I add my test command in there it does work

"scripts": {
    "test" : " ... ",
    ...
}

Any suggestions how I can add commands in there ?

Upvotes: 0

Views: 98

Answers (1)

alexmac
alexmac

Reputation: 19617

run is a registered npm command (command ro run Lifecycle scripts), so to execute your command you should call run twice:

npm run run

or use start instead:

"scripts": {
    "start": "./node_modules/babel/bin/babel-node.js index.js"
},

And to start:

npm start

Upvotes: 1

Related Questions