Beyond managing packages, npm can execute tasks the way Grunt and Gulp do—which is useful once a package like Sass has been installed locally and you want to put it to work.
The scripts property
Open package.json in your test folder and you'll see only a single dependencies property so far. The file holds much more than dependencies, though: it carries metadata about the project, and one of its most useful optional entries is scripts.
Keep the split clear: package-lock.json is generated automatically, tracks Sass's sub-dependencies, and should not be edited by hand. package.json lists only top-level dependencies and is yours to customize.
The scripts object defines commands you can run within that project, either as one-shots or as long-running processes. Typical tasks include launching a local dev server, compiling assets, and running tests; many projects ship a single start or dev command that chains everything needed at once, such as compiling Sass and JavaScript together.
Building a Sass compile step
Everything installed in the project is reachable from inside scripts. You cannot type sass commands directly in the terminal right now—that requires a global, system-wide install—but within an npm script those commands work.
Paste the following block into package.json, immediately after the opening {:
"scripts": {
"sass:build": "sass style.scss style.css"
},
That gives you npm run sass:build, which compiles Sass to CSS. JSON is strict, so run the file through a JSON validator if you get stuck.
The script's name can be anything as long as it is one continuous string. The colon in sass:build has no special meaning—it is convention, since build or sass alone would be too generic.
The command expects a style.scss file at the project root. Create one with some Sass in it and save it:
$myColor: #ffd100;
.a {
.nested {
.selector {
color: $myColor;
}
}
}
Now run the command:
npm run sass:build
Within moments, two new files should appear: style.css and style.css.map. Opening style.css shows the compiled CSS. The sass package also emits a source map, so browser DevTools can show which .scss files produced a given style.
If you hit an error, check three things: that package.json is valid JSON (an online JSON validator helps), that the .scss file contains valid Sass (an online Sass-to-CSS converter can confirm), and that the file name matches the name used in the command.
Watching for changes
Re-running the build by hand gets tedious during development. A second script lets Sass watch the file and recompile on every save. Add this inside the scripts object:
"sass:watch": "sass style.scss style.css --watch"
The order of the two scripts doesn't matter, but the comma between them does—JSON is strict again.
Running sass:watch prints "Sass is watching for changes. Press Ctrl-C to stop." Modify style.scss and save, and the terminal reports that the Sass has recompiled into CSS:

Once these files are committed to the repo, anyone on the project has the exact directions needed to install Sass and run it with a single command.
Install scopes worth knowing
npm packages can be installed two ways, and the right choice depends on whether the package belongs in the production build or only in development.
npm install(ornpm i) is the standard, default install for a project.npm install --save-dev(ornpm i -D) records the package as a dev dependency, installed only during development and not when the finalized production build is made. Testing libraries, linters, and preview servers fall in this group—tools that help you develop but don't compile or run the site itself.
One more flag: npm install --global (or npm i -g) installs system-wide, which is how you'd make sass available anywhere on your machine. Other common uses are CLI tools you want everywhere, or another package manager such as Yarn.
In practice you'll usually reach for a pre-configured project rather than writing npm commands from scratch—which is where the next chapter picks up, with installing an existing npm project.



