Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

PoJung Chen
PoJung Chen
5,856 Points

why use "npm start" but not "npm run start"?

In the last video, we use "npm run build" to execute the script. Why we only use "npm start" and npm can still run it?

Lean Rasmussen
Lean Rasmussen
11,060 Points

Just tried. You can use npm run start. It works fine in my own projekt. npm start is just shorter.

PoJung Chen
PoJung Chen
5,856 Points

I can use "npm run start", but I can not use "npm build" as a shortcut, what's the logic behind ?

1 Answer

Take a look at the "scripts" field.

scripts

The "scripts" property is a dictionary containing script commands that are run at various times in the lifecycle of your package. The key is the lifecycle event, and the value is the command to run at that point.

See npm-scripts to find out more about writing package scripts.

npm supports the "scripts" property of the package.json script, for the following scripts:

prestart, start, poststart: Run by the npm start command.

You don't have a build task in your scripts field.