From 1ab017fa0b37424bfc8eaf760c086c0ca9a2699a Mon Sep 17 00:00:00 2001 From: Frankie Roberto Date: Wed, 13 Nov 2024 23:46:25 +0000 Subject: [PATCH 1/3] Add instructions if you run npm start 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 adds a console message to say: > 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 | 5 +++++ gulpfile.js | 8 +++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app.js b/app.js index f438feaf..064cb86b 100755 --- a/app.js +++ b/app.js @@ -234,6 +234,11 @@ app.use((err, req, res) => { res.send(err.message); }); +if (process.env.WATCH !== 'true') { + console.log(`Running at http://localhost:${port}/`); // eslint-disable-line no-console + console.log('\x1b[36m \nIf you are working on this prototype now, press Control-c to stop the server and \ntype \x1b[34mnpm run watch\x1b[36m instead to run the prototype in development mode.\x1b[0m'); // eslint-disable-line no-console +} + // Run the application app.listen(port); diff --git a/gulpfile.js b/gulpfile.js index 3f85d179..f910e2f8 100755 --- a/gulpfile.js +++ b/gulpfile.js @@ -113,13 +113,19 @@ function watch() { gulp.watch('docs/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)); From 5e6ce107ef536bb492f8a20aa661c42d0c5fed3f Mon Sep 17 00:00:00 2001 From: Frankie Roberto Date: Thu, 14 Nov 2024 21:48:49 +0000 Subject: [PATCH 2/3] =?UTF-8?q?Don=E2=80=99t=20show=20the=20message=20when?= =?UTF-8?q?=20running=20in=20production?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app.js b/app.js index 064cb86b..9e862831 100755 --- a/app.js +++ b/app.js @@ -234,9 +234,12 @@ app.use((err, req, res) => { res.send(err.message); }); -if (process.env.WATCH !== 'true') { - console.log(`Running at http://localhost:${port}/`); // eslint-disable-line no-console - console.log('\x1b[36m \nIf you are working on this prototype now, press Control-c to stop the server and \ntype \x1b[34mnpm run watch\x1b[36m instead to run the prototype in development mode.\x1b[0m'); // eslint-disable-line no-console +if ( + process.env.WATCH !== 'true' // If the user isn’t running watch + && process.env.NODE_ENV !== 'production' // and it’s not in production mode +) { + console.info(`Running at http://localhost:${port}/`); // eslint-disable-line no-console + console.warn('\x1b[36m \nIf you are working on this prototype now, press Control-c to stop the server and \ntype \x1b[34mnpm run watch\x1b[36m instead to run the prototype in development mode.\x1b[0m'); // eslint-disable-line no-console } // Run the application From 34f440e9f9e45ba208f949facead03618ee29e0f Mon Sep 17 00:00:00 2001 From: Frankie Roberto Date: Tue, 10 Dec 2024 22:09:45 +0000 Subject: [PATCH 3/3] Update warning text --- app.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/app.js b/app.js index 18773cb5..abfee894 100755 --- a/app.js +++ b/app.js @@ -208,15 +208,19 @@ app.use((err, req, res) => { res.send(err.message); }); +// 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 ) { - console.info(`Running at http://localhost:${port}/`); // eslint-disable-line no-console - console.warn('\x1b[36m \nIf you are working on this prototype now, press Control-c to stop the server and \ntype \x1b[34mnpm run watch\x1b[36m instead to run the prototype in development mode.\x1b[0m'); // eslint-disable-line no-console + /* 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 */ } -// Run the application -app.listen(port); - module.exports = app;