Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.