<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>nx &amp;mdash; Simple Engineering</title>
    <link>https://getsimple.works/tag:nx</link>
    <description></description>
    <pubDate>Mon, 20 Apr 2026 18:13:25 +0000</pubDate>
    <item>
      <title>nodejs development workflow</title>
      <link>https://getsimple.works/nodejs-development-workflow?pk_campaign=rss-feed</link>
      <description>&lt;![CDATA[This blog post highlights key points to consider when setting up a nodejs application workflow. &#xA;&#xA;In this article we will talk about: &#xA;&#xA;Key workflow that requires automation&#xA;Automating workflow using npm &#xA;Automating workflow using gulp &#xA;Inter-operable workflow using npm and gulp&#xA;Other tools: nx &#xA;Auto reload(hot reload) using:nodemon, supervisor or forever&#xA;&#xA;  Even though this blog post was designed to offer complementary materials to those who bought my Testing nodejs Applications book, the content can help any software developer to tuneup working environment. You use this link to buy the book.  Testing nodejs Applications Book Cover&#xA;&#xA;Key automation opportunities&#xA;&#xA;Automation opportunities are grouped around tasks that tend to be manually repeated, over the course of the development lifecycle. Some of those opportunities are, but not limited to: &#xA;&#xA;hot reloading the server after updating some source files&#xA;automatically executing tests after source/test code change &#xA;pre-commit lint/test/cleaning hooks&#xA;&#xA;To name a few. There are two major workflow automation tools that are discussed in this article, but the process will be applicable to any tool the reader wishes to pick. Those tools are, but not limited to npm, yarn, gulp -- and husky for git hooks.&#xA;&#xA;Hot reload can be achieved using one of the following tools: nodemon, supervisor or forever. The choice of tools does not end here, as there is always something cooking in the community. To start a server in watch mode, instead of starting the server as: node server.js, we can use instead supervisor server.js. Later in the following sections, we will see how we can move this feature from the command line to npm scripts, or even to gulp tasks runner helper.&#xA;&#xA;Workflow with npm&#xA;&#xA;There are various issues related to relying on npm package globally installed on one system. Some of those issues are exposed when code changes hands and runs on another platform: deployment server, CI server, or even a developer computer other than ours. The npm package version provided globally, may not be the npm package version required by the project at hand. There is no indication to tell npm to use local package A instead of globally available package B. To eliminate that ambiguity, taking preference on all modules local to the project makes sense.&#xA;&#xA;  How to manage globally installed devDependencies ~ StackOverflow Question. How to Solve the Global npm Module Dependency Problem&#xA;&#xA;Workflow with gulp&#xA;&#xA;Running this to a remote server requires installing manually a global version of gulp. Many applications, may require a different gulp version. Typical gulp installation:&#xA;&#xA;$ npm install gulp -g     #provides gulp cli globally&#xA;$ npm install gulp --save #provides gulp locally &#xA;&#xA;Since some applications may require a different version of gulp, adding gulp in package.json as in the following example makes sure the locally sourced gulp is run. &#xA;&#xA;&#34;scripts&#34;: {&#xA;  &#34;gulp&#34;: &#34;./nodemodules/.bin/gulp&#34;  &#xA;}&#xA;Example: equivalent to gulp when installed globally&#xA;&#xA;Use case: running mocha test with npm&#xA;&#xA;This section highlights important steps to get tests up and running. Examples provided here cover single runs, as well as watch mode. &#xA;&#xA;While searching for a task runner, stability ease of use, and reporting capabilities come first. Even though mocha is easy to get started, other tools such as jasmine-node/ava or jest can do a pretty good job at a testing node as well. They worth giving a try. &#xA;&#xA;supertest is a testing utility wrapper of superagent. It is useful when testing endpoints of REST API in end-to-end/contract/integration test scenarios. However, when working on unit tests, for that reason there is a need to intercept HTTP requests, mocking tools such as nock HTTP mocking framework deserves a chance.  &#xA;&#xA;Starting with command line test runner instructions, gives a pretty good baseline and an idea of how the npm script may end-up looking like.  The following example, showcases how to run tests in watch mode, while instrumenting a select set of source code files for reporting purposes:&#xA;&#xA;$ ./nodemodules/.bin/istanbul cover \&#xA;    --dir ./test/coverage -i &#39;lib/&#39; \&#xA;    ./nodemodules/.bin/mocha -- --reporter \&#xA;    spec  test//spec.js&#xA;&#xA;istanbul is a reporting tool and will be used to generate reports, as tests progress. &#xA;&#xA;in package.json at &#34;test&#34; - add next line&#xA;$ istanbul test mocha -- --color --reporter mocha-lcov-reporter specs&#xA;then run the tests using &#xA;&#xA;In case that code works just fine, we can go ahead and add it in the scripts section of package.json, and that will be enough to execute the test runner command from npm&#xA;&#xA;  There are additional features that make this setup a little more hectic to work with. Even though mocha is the choice of this blog, jest is also a pretty good alternative to the test node too. &#xA;&#xA;{&#xA;  &#34;test&#34;: &#34;mocha -R spec  test//spec.js&#34;,&#xA;  &#34;test:compile&#34;: &#34;mocha -R spec --compilers js:babel/register test/*/spec.js&#34;,&#xA;  &#34;watch&#34;: &#34;npm test -- --watch&#34;,&#xA;  //Adding istanbul coverage + local istanbul + local mocha &#xA;  &#34;test&#34;: &#34;./nodemodules/.bin/istanbul cover --dir ./test/coverage -i &#39;lib/&#39; ./nodemodules/.bin/mocha -- --reporter spec  test//spec.js&#34;,&#xA;  //./nodemodules/.bin/istanbul cover --dir ./test/coverage -i &#39;lib/&#39; ./nodemodules/.bin/mocha -- --reporter spec  test//spec.js =  produces&lt;= &#34;No coverage information was collected, exit without writing coverage information&#34; &#xA;}&#xA;&#xA;  When using istanbul cover mocha - Error: &#34;No coverage information was collected, exit without writing coverage information&#34; may be displayed. To avoid this error, the use of istanbul cover mocha can make reporting available at the end of test execution.&#xA;&#xA;Once the npm scripts are in place, we can leverage the command line once again, but this time using a smaller version of the command. We have to keep in mind that, most environments have to have npm available globally.&#xA;&#xA;$ npm test --coverage&#xA;$ npm run test:watch&#xA;$ npm run test:compile&#xA;&#xA;Use case: running mocha test with gulp&#xA;&#xA;$ npm run gulp will use scripts   gulp version. The reason for using gulp while testing, is to have a smaller package.json scripts section. The tasks have to be written in ./gulpfile.js, and requires gulp plugins to work. gulp tasks can also take on more complex custom tasks such as deployment from the local machine, codemod and other various tasks using projects that do not have a cli tool yet. &#xA;&#xA;Conclusion&#xA;&#xA;In this article, we revisited key points to set up a nodejs workflow. The workflow explored goes from writing code to automated tasks such as linting, testing, and release. There are additional complimentary materials in the &#34;Testing nodejs applications&#34; book.  &#xA;&#xA;References&#xA;&#xA;Testing nodejs Applications book&#xA;The no coverage information issue was resolved using in this github ~ issue #262, issue #496 and issue #798&#xA;Difference between mocha and mocha &#xA;Source: unit test node code in 10 seconds&#xA;Source: Istanbul Cover&#xA;npm + mocha --watch not accurately watching files&#xA;&#xA;#snippets #nodejs #workflow #npm #nx]]&gt;</description>
      <content:encoded><![CDATA[<p>This blog post highlights key points to consider when setting up a <code>nodejs</code> application workflow.</p>

<p><strong><em>In this article we will talk about:</em></strong></p>
<ul><li>Key workflow that requires automation</li>
<li>Automating workflow using <code>npm</code></li>
<li>Automating workflow using <code>gulp</code></li>
<li>Inter-operable workflow using <code>npm</code> and <code>gulp</code></li>
<li>Other tools: <a href="https://nx.io"><code>nx</code></a></li>
<li>Auto reload(hot reload) using:<code>nodemon</code>, <code>supervisor</code> or <code>forever</code></li></ul>

<blockquote><p>Even though this blog post was designed to offer complementary materials to those who bought my <strong><em><a href="https://bit.ly/2ZFJytb">Testing <code>nodejs</code> Applications book</a></em></strong>, the content can help any software developer to tuneup working environment. <strong><em><a href="https://bit.ly/2ZFJytb">You use this link to buy the book</a></em></strong>.  <a href="https://bit.ly/2ZFJytb"><img src="https://snap.as/a/42OS2vs.png" alt="Testing nodejs Applications Book Cover"/></a></p></blockquote>

<h2 id="key-automation-opportunities" id="key-automation-opportunities">Key automation opportunities</h2>

<p>Automation opportunities are grouped around tasks that tend to be manually repeated, over the course of the development lifecycle. Some of those opportunities are, but not limited to:</p>
<ul><li>hot reloading the server after updating some source files</li>
<li>automatically executing tests after source/test code change</li>
<li>pre-commit lint/test/cleaning hooks</li></ul>

<p>To name a few. There are two major workflow automation tools that are discussed in this article, but the process will be applicable to any tool the reader wishes to pick. Those tools are, but not limited to <code>npm</code>, <code>yarn</code>, <code>gulp</code> — and <code>husky</code> for git hooks.</p>

<p>Hot reload can be achieved using one of the following tools: <code>nodemon</code>, <code>supervisor</code> or <code>forever</code>. The choice of tools does not end here, as there is always something cooking in the community. To start a server in watch mode, instead of starting the server as: <code>node server.js</code>, we can use instead <code>supervisor server.js</code>. Later in the following sections, we will see how we can move this feature from the command line to <code>npm</code> scripts, or even to <code>gulp</code> tasks runner helper.</p>

<h2 id="workflow-with-npm" id="workflow-with-npm">Workflow with <code>npm</code></h2>

<p>There are various issues related to relying on <code>npm</code> package globally installed on one system. Some of those issues are exposed when code changes hands and runs on another platform: deployment server, CI server, or even a developer computer other than ours. The <code>npm</code> package version provided globally, may not be the <code>npm</code> package version required by the project at hand. There is no indication to tell <code>npm</code> to use local package A instead of globally available package B. To eliminate that ambiguity, taking preference on all modules local to the project makes sense.</p>

<blockquote><p><a href="https://stackoverflow.com/a/17220243/132610">How to manage globally installed devDependencies ~ StackOverflow Question</a>. <a href="https://www.sitepoint.com/solve-global-npm-module-dependency-problem/">How to Solve the Global <code>npm</code> Module Dependency Problem</a></p></blockquote>

<h2 id="workflow-with-gulp" id="workflow-with-gulp">Workflow with <code>gulp</code></h2>

<p>Running this to a remote server requires installing manually a global version of gulp. Many applications, may require a different gulp version. Typical <code>gulp</code> installation:</p>

<pre><code class="language-shell">$ npm install gulp -g     #provides gulp `cli` globally
$ npm install gulp --save #provides gulp locally 
</code></pre>

<p>Since some applications may require a different version of <code>gulp</code>, adding gulp in <code>package.json</code> as in the following example makes sure the locally sourced <code>gulp</code> is run.</p>

<pre><code class="language-json">&#34;scripts&#34;: {
  &#34;gulp&#34;: &#34;./node_modules/.bin/gulp&#34;  
}
</code></pre>

<p><em><em>Example</em>: equivalent to gulp when installed globally</em></p>

<h2 id="use-case-running-mocha-test-with-npm" id="use-case-running-mocha-test-with-npm">Use case: running <code>mocha</code> test with <code>npm</code></h2>

<p>This section highlights important steps to get tests up and running. Examples provided here cover single runs, as well as watch mode.</p>

<p>While searching for a task runner, stability ease of use, and reporting capabilities come first. Even though <code>mocha</code> is easy to get started, other tools such as <code>jasmine-node</code>/<code>ava</code> or <code>jest</code> can do a pretty good job at a testing node as well. They worth giving a try.</p>

<p><code>supertest</code> is a testing utility wrapper of <code>superagent</code>. It is useful when testing endpoints of REST API in end-to-end/contract/integration test scenarios. However, when working on unit tests, for that reason there is a need to intercept HTTP requests, mocking tools such as <a href="https://github.com/pgte/nock"><code>nock</code></a> HTTP mocking framework deserves a chance.</p>

<p>Starting with command line test runner instructions, gives a pretty good baseline and an idea of how the <code>npm</code> script may end-up looking like.  The following example, showcases how to run tests in watch mode, while instrumenting a select set of source code files for reporting purposes:</p>

<pre><code class="language-shell">$ ./node_modules/.bin/istanbul cover \
    --dir ./test/coverage -i &#39;lib/**&#39; \
    ./node_modules/.bin/_mocha -- --reporter \
    spec  test/**/*spec.js
</code></pre>

<p><code>istanbul</code> is a reporting tool and will be used to generate reports, as tests progress.</p>

<pre><code class="language-shell"># in package.json at &#34;test&#34; - add next line
$ istanbul test mocha -- --color --reporter mocha-lcov-reporter specs
# then run the tests using 
</code></pre>

<p>In case that code works just fine, we can go ahead and add it in the scripts section of <code>package.json</code>, and that will be enough to execute the test runner command from <code>npm</code></p>

<blockquote><p> There are additional features that make this setup a little more hectic to work with. Even though <code>mocha</code> is the choice of this blog, <code>jest</code> is also a pretty good alternative to the test node too.</p></blockquote>

<pre><code class="language-json">{
  &#34;test&#34;: &#34;mocha -R spec  test/**/*spec.js&#34;,
  &#34;test:compile&#34;: &#34;mocha -R spec --compilers js:babel/register test/**/*spec.js&#34;,
  &#34;watch&#34;: &#34;npm test -- --watch&#34;,
  //Adding istanbul coverage + local istanbul + local mocha 
  &#34;test&#34;: &#34;./node_modules/.bin/istanbul cover --dir ./test/coverage -i &#39;lib/**&#39; ./node_modules/.bin/mocha -- --reporter spec  test/**/*spec.js&#34;,
  //./node_modules/.bin/istanbul cover --dir ./test/coverage -i &#39;lib/**&#39; ./node_modules/.bin/mocha -- --reporter spec  test/**/*spec.js =&gt;produces&lt;= &#34;No coverage information was collected, exit without writing coverage information&#34; 
}
</code></pre>

<blockquote><p>When using <code>istanbul cover mocha</code> – Error: <strong>“No coverage information was collected, exit without writing coverage information”</strong> may be displayed. To avoid this error, the use of <code>istanbul cover _mocha</code> can make reporting available at the end of test execution.</p></blockquote>

<p>Once the <code>npm</code> scripts are in place, we can leverage the command line once again, but this time using a smaller version of the command. We have to keep in mind that, most environments have to have <code>npm</code> available globally.</p>

<pre><code class="language-shell">$ npm test --coverage
$ npm run test:watch
$ npm run test:compile
</code></pre>

<h2 id="use-case-running-mocha-test-with-gulp" id="use-case-running-mocha-test-with-gulp">Use case: running <code>mocha</code> test with <code>gulp</code></h2>

<p><code>$ npm run gulp</code> will use <code>scripts &gt; gulp</code> version. The reason for using <code>gulp</code> while testing, is to have a smaller <code>package.json</code> scripts section. The tasks have to be written in ./<code>gulpfile.js</code>, and requires gulp plugins to work. <code>gulp</code> tasks can also take on more complex custom tasks such as deployment from the local machine, <code>codemod</code> and other various tasks using projects that do not have a <code>cli</code> tool yet.</p>

<h2 id="conclusion" id="conclusion">Conclusion</h2>

<p>In this article, we revisited key points to set up a <code>nodejs</code> workflow. The workflow explored goes from writing code to automated tasks such as linting, testing, and release. There are additional complimentary materials in the <strong>“Testing <code>nodejs</code> applications”</strong> book.</p>

<h2 id="references" id="references">References</h2>
<ul><li><a href="https://bit.ly/2ZFJytb">Testing <code>nodejs</code> Applications book</a></li>
<li>The no coverage information issue was resolved using in this <a href="https://github.com/gotwarlost/istanbul/issues/262">github ~ issue #262</a>, <a href="https://github.com/gotwarlost/istanbul/issues/496">issue #496</a> and <a href="https://github.com/gotwarlost/istanbul/issues/798">issue #798</a></li>
<li>Difference between <a href="https://github.com/gotwarlost/istanbul/issues/436#issuecomment-139461731"><code>mocha</code> and <code>_mocha</code></a></li>
<li><strong><a href="https://glebbahmutov.com/blog/unit-test-node-code-in-10-seconds/">Source: unit test node code in 10 seconds</a></strong></li>
<li><strong><a href="https://github.com/gotwarlost/istanbul#the-cover-command">Source: Istanbul Cover</a></strong></li>
<li><strong><a href="https://stackoverflow.com/q/22823173/132610"><code>npm</code> + <code>mocha --watch</code> not accurately watching files</a></strong></li></ul>

<p><a href="https://getsimple.works/tag:snippets" class="hashtag"><span>#</span><span class="p-category">snippets</span></a> <a href="https://getsimple.works/tag:nodejs" class="hashtag"><span>#</span><span class="p-category">nodejs</span></a> <a href="https://getsimple.works/tag:workflow" class="hashtag"><span>#</span><span class="p-category">workflow</span></a> <a href="https://getsimple.works/tag:npm" class="hashtag"><span>#</span><span class="p-category">npm</span></a> <a href="https://getsimple.works/tag:nx" class="hashtag"><span>#</span><span class="p-category">nx</span></a></p>
]]></content:encoded>
      <guid>https://getsimple.works/nodejs-development-workflow</guid>
      <pubDate>Thu, 17 Jun 2021 05:04:35 +0000</pubDate>
    </item>
  </channel>
</rss>