File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- const express = require ( "express" ) ;
1+ // app.js
2+ const express = require ( "express" ) ;
23const app = express ( ) ;
34
5+ // keep the old test string for the unit test
6+ function hello ( ) {
7+ return "Hello from MyApp - dev" ;
8+ }
9+
10+ // public route shows CI/CD message
411app . get ( "/" , ( req , res ) => {
512 res . send ( "Hello from MyApp - CI/CD Working!" ) ;
613} ) ;
714
8- const PORT = process . env . PORT || 3000 ;
9- app . listen ( PORT , ( ) => {
10- console . log ( `Server running on port ${ PORT } ` ) ;
11- } ) ;
15+ // export the Express app and the hello() function for tests
16+ module . exports = { app, hello } ;
1217
13- module . exports = app ;
18+ // Only start the server when this file is run directly (node app.js),
19+ // not when imported by tests (require).
20+ if ( require . main === module ) {
21+ const PORT = process . env . PORT || 3000 ;
22+ app . listen ( PORT , ( ) => {
23+ // only log when actually starting the server
24+ console . log ( `Server running on port ${ PORT } ` ) ;
25+ } ) ;
26+ }
You can’t perform that action at this time.
0 commit comments