title: nodemon : clean exit waiting for changes before restart
body: <p>Hello I do not understand I can not play server anymore.</p>
  <p>.env PORT=4000</p>
  <p>server.listen is exported in start.ts for the tests to work without saying &quot;PORT is already busy&quot;</p>
  <p>My project is typescript, express, jest api.</p>
  <p>When I &quot;npm run dev&quot; I got no connection on localhost:4000:</p>
  <pre><code>spark-administration-bff|automaticSwagger⚡ ⇒ npm run dev
  
  &gt; spark_backend@1.0.0 dev /Users/julie/Documents/groupe_rocher/spark-administration/spark-administration-bff
  &gt; nodemon
  
  [nodemon] 2.0.4
  [nodemon] to restart at any time, enter `rs`
  [nodemon] watching path(s): src/**/*
  [nodemon] watching extensions: ts
  [nodemon] starting `npm start`
  
  &gt; spark_backend@1.0.0 start /Users/julie/Documents/groupe_rocher/spark-administration/spark-administration-bff
  &gt; node dist/src/index.js
  
  [nodemon] clean exit - waiting for changes before restart
  _____________________________
  </code></pre>
  <p>When I &quot;npm test&quot; :
  I got first &quot;[nodemon] clean exit - waiting for changes before restart&quot; then if I &quot;ctrl C&quot;:</p>
  <p>the tests are all running green PASS, with just 2 warnings:</p>
  <p>(node:4549) UnhandledPromiseRejectionWarning: Error: connect ECONNREFUSED 127.0.0.1:80
  at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1141:16)
  (node:4549) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block,...</p>
  <p>#project tree</p>
  <pre><code>
  /dist
  |__src
     |__index.js
     |__start.js
  /src
  |__modules
  |__routes
  |__index.ts
  |__start.ts
  /tests
  </code></pre>
  <p>#Package.json</p>
  <pre><code>
  {
    &quot;name&quot;: &quot;spark_backend&quot;,
    &quot;version&quot;: &quot;1.0.0&quot;,
    &quot;description&quot;: &quot;&quot;,
    &quot;main&quot;: &quot;./dist/src/index.js&quot;,
    &quot;scripts&quot;: {
      &quot;prebuilt&quot;: &quot;tslint -c tslint.json -p tsconfig.json --fix&quot;,
      &quot;build&quot;: &quot;tsc&quot;,
      &quot;watch&quot;: &quot;concurrently --kill-others npm:watch-*&quot;,
      &quot;watch typescript&quot;: &quot;tsc -w&quot;,
      &quot;watch-node&quot;: &quot;nodemon dist/index.js&quot;,
      &quot;pretest&quot;: &quot;cross-env NODE_ENV=test npm run dev&quot;,
      &quot;test&quot;: &quot;cross-env NODE_ENV=test jest --verbose --watchAll --forceExit --maxWorkers=1&quot;,
      &quot;start&quot;: &quot;node .&quot;,
      &quot;start-dev&quot;: &quot;nodemon index.ts&quot;,
      &quot;dev&quot;: &quot;nodemon&quot;
    },
    &quot;keywords&quot;: [],
    &quot;author&quot;: &quot;&quot;,
    &quot;license&quot;: &quot;ISC&quot;,
    &quot;dependencies&quot;: {
      &quot;axios&quot;: &quot;^0.19.2&quot;,
      &quot;concurrently&quot;: &quot;^5.2.0&quot;,
      &quot;cors&quot;: &quot;^2.8.5&quot;,
      &quot;cross-env&quot;: &quot;^7.0.2&quot;,
      &quot;dotenv&quot;: &quot;^8.2.0&quot;,
      &quot;express&quot;: &quot;^4.17.1&quot;,
      &quot;express-formidable&quot;: &quot;^1.2.0&quot;,
      &quot;git-flow&quot;: &quot;^0.2.0&quot;,
      &quot;nodemon&quot;: &quot;^2.0.4&quot;,
      &quot;swagger-jsdoc&quot;: &quot;^4.0.0&quot;,
      &quot;swagger-ui-express&quot;: &quot;^4.1.4&quot;,
      &quot;ts-jest&quot;: &quot;^26.1.3&quot;
    },
    &quot;devDependencies&quot;: {
      &quot;@commitlint/cli&quot;: &quot;^9.1.1&quot;,
      &quot;@types/cors&quot;: &quot;^2.8.6&quot;,
      &quot;@types/dotenv&quot;: &quot;^8.2.0&quot;,
      &quot;@types/express&quot;: &quot;^4.17.7&quot;,
      &quot;@types/express-formidable&quot;: &quot;^1.0.4&quot;,
      &quot;@types/jest&quot;: &quot;^26.0.5&quot;,
      &quot;@types/node&quot;: &quot;^14.0.23&quot;,
      &quot;@types/supertest&quot;: &quot;^2.0.10&quot;,
      &quot;@types/swagger-jsdoc&quot;: &quot;^3.0.2&quot;,
      &quot;@types/swagger-ui-express&quot;: &quot;^4.1.2&quot;,
      &quot;jest&quot;: &quot;^26.1.0&quot;,
      &quot;supertest&quot;: &quot;^4.0.2&quot;,
      &quot;tslint&quot;: &quot;^6.1.2&quot;,
      &quot;typescript&quot;: &quot;^3.9.6&quot;
    },
    &quot;jest&quot;: {
      &quot;testEnvironment&quot;: &quot;node&quot;,
      &quot;coveragePathIgnorePatterns&quot;: [
        &quot;/nodes_modules&quot;
      ]
    }
  }
  </code></pre>
  <p>#start.ts</p>
  <pre><code>const server = require(&quot;./index&quot;);
  
  server.listen(process.env.PORT, () =&gt; {
    // tslint:disable-next-line:no-console
    console.log(&quot;encore sylvie started&quot;);
  });
  </code></pre>
  <p>#index.ts</p>
  <pre><code>require(&quot;dotenv&quot;).config();
  import express from &quot;express&quot;;
  const formidableMiddleware = require(&quot;express-formidable&quot;);
  import cors from &quot;cors&quot;;
  import swaggerUi from &quot;swagger-ui-express&quot;;
  import * as SwaggerDocument from &quot;./swagger.json&quot;;
  
  const server: express.Application = express();
  server.use(formidableMiddleware());
  server.use(cors());
  
  // swagger
  server.use(&quot;/api-docs&quot;, swaggerUi.serve, swaggerUi.setup(SwaggerDocument));
  
  // ROUTES 
  
  const usersRoute = require(&quot;./routes/Users&quot;);
  server.use(usersRoute);
  
  const customersRoute = require(&quot;./routes/Customers&quot;);
  server.use(customersRoute);
  
  // OTHERS
  
  server.get(&quot;/&quot;, (req: any, res: any) =&gt; {
    res.send(&quot;Welcome to Spark Admin back end!&quot;);
  });
  
  server.all(&quot;*&quot;, (req: any, res: any) =&gt; {
    res.status(404).json({ error: &quot;Web url not found&quot; });
  });
  
  module.exports = server;
  </code></pre>
  <p>#example of test:</p>
  <pre><code>import express from &quot;express&quot;;
  const server = require(&quot;../../src/index&quot;);
  const request = require(&quot;supertest&quot;)(server);
  
  describe(&quot;user connexion giving token&quot;, function () {
    it('should respond with 400 : miss &quot;client_credentials&quot; as grant_type', async function (done) {
      request
        .post(&quot;/users/oauth&quot;)
        .expect(400)
        .end(function (err: any) {
          if (err) return done(err);
          done();
        });
    });
  });
  </code></pre>
  <p>#tsconfig just in case:</p>
  <pre><code>{
    &quot;compilerOptions&quot;: {
      &quot;module&quot;: &quot;commonjs&quot;,
      &quot;resolveJsonModule&quot;: true,
      &quot;esModuleInterop&quot;: true,
      &quot;target&quot;: &quot;es6&quot;,
      &quot;noImplicitAny&quot;: true,
      &quot;moduleResolution&quot;: &quot;node&quot;,
      &quot;declaration&quot;: true,
      &quot;sourceMap&quot;: true,
      &quot;outDir&quot;: &quot;./dist&quot;,
      &quot;strict&quot;: true,
      &quot;baseUrl&quot;: &quot;.&quot;,
      &quot;paths&quot;: {
        &quot;*&quot;: [&quot;node_modules/*&quot;]
      },
      &quot;typeRoots&quot;: [&quot;./types&quot;, &quot;./node_modules/@types&quot;]
    },
    &quot;include&quot;: [&quot;src&quot;, &quot;tests&quot;],
    &quot;types&quot;: [&quot;jest&quot;, &quot;node&quot;]
  }
  </code></pre>