Skip to content

Commit

Permalink
Add instructions if you run npm start (#411)
Browse files Browse the repository at this point in the history
Currently if you run `npm start`, which is the common default start
command for Node.js apps, then in the console you don’t see any messages
and it looks like nothing is working. However it is working, just on the
uncommon default port of 2000 (set in `config.js`).

This confused me and several others at first. The guidance to use `npm
run watch` has since been [added to the README](#284) but is easily
missed.

This change aims to further help, by adding a console message saying:

> Running at http://localhost:2000/
>
> If you are working on this prototype now, press Control-C to stop the
server and
> type npm run watch instead to run the prototype in development mode.

This message is not shown when running `npm run watch`, as there the
BrowserSync service will display the proxied localhost port to view the
prototype on.
  • Loading branch information
frankieroberto authored Dec 13, 2024
1 parent c3fe03f commit de55c94
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
12 changes: 12 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,4 +211,16 @@ app.use((err, req, res) => {
// Run the application
app.listen(port);

if (
process.env.WATCH !== 'true' // If the user isn’t running watch
&& process.env.NODE_ENV !== 'production' // and it’s not in production mode
) {
/* eslint-disable no-console */
console.info(`Running at http://localhost:${port}/`);
console.info('');
console.warn('Warning: It looks like you may have run the command `npm start` locally.');
console.warn('Press `Ctrl+C` and then run `npm run watch` instead');
/* eslint-enable no-console */
}

module.exports = app;
8 changes: 7 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,19 @@ function watch() {
gulp.watch('app/assets/**/**/*.*', compileAssets);
}

function setWatchEnv(done) {
process.env.WATCH = 'true';
done();
}

exports.watch = watch;
exports.compileStyles = compileStyles;
exports.compileScripts = compileScripts;
exports.cleanPublic = cleanPublic;
exports.setWatchEnv = setWatchEnv;

gulp.task(
'build',
gulp.series(cleanPublic, compileStyles, compileScripts, compileAssets)
);
gulp.task('default', gulp.series(startNodemon, startBrowserSync, watch));
gulp.task('default', gulp.series(setWatchEnv, startNodemon, startBrowserSync, watch));

0 comments on commit de55c94

Please sign in to comment.