From de55c94d8e71d5f9bc692914e5891ed20c47b6f9 Mon Sep 17 00:00:00 2001 From: Frankie Roberto Date: Fri, 13 Dec 2024 14:41:37 +0000 Subject: [PATCH] Add instructions if you run npm start (#411) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- app.js | 12 ++++++++++++ gulpfile.js | 8 +++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/app.js b/app.js index 15e298b7..6c9f59dc 100755 --- a/app.js +++ b/app.js @@ -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; diff --git a/gulpfile.js b/gulpfile.js index 1941de66..c9362017 100755 --- a/gulpfile.js +++ b/gulpfile.js @@ -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));