<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Jon Cammisuli</title>
    <description>The latest articles on DEV Community by Jon Cammisuli (@cammisuli).</description>
    <link>https://dev.to/cammisuli</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F117106%2F3055220d-5cef-4abf-9e6f-629f6fa8d834.png</url>
      <title>DEV Community: Jon Cammisuli</title>
      <link>https://dev.to/cammisuli</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/cammisuli"/>
    <language>en</language>
    <item>
      <title>Building Node Apps with Nx Dev Tools</title>
      <dc:creator>Jon Cammisuli</dc:creator>
      <pubDate>Mon, 26 Oct 2020 18:13:24 +0000</pubDate>
      <link>https://dev.to/nx/building-node-apps-with-nx-dev-tools-2o8b</link>
      <guid>https://dev.to/nx/building-node-apps-with-nx-dev-tools-2o8b</guid>
      <description>&lt;p&gt;In this article we will go through different tools and techniques that we can use to build applications and libraries for use with Node. &lt;/p&gt;




&lt;p&gt;&lt;a href="https://nx.dev"&gt;Nx&lt;/a&gt; and &lt;a href="https://nodejs.org"&gt;Node&lt;/a&gt; have always been able to work well together.  We have &lt;a href="https://nx.dev/latest/node/plugins/overview"&gt;schematics for creating Node apps (Express, Nest) and Node libraries (TypeScript)&lt;/a&gt;. Then we have builders to run those specific apps, or build those libraries for publishing. &lt;/p&gt;

&lt;p&gt;With these tools, we're able to achieve a lot of things that are possible with Node. With the examples below we can discuss some simple use cases.  &lt;/p&gt;

&lt;h2&gt;
  
  
  Creating Node Applications (fun with APIs)
&lt;/h2&gt;

&lt;p&gt;If you're starting out with a new project, and you know that you'll be focusing on the API side of things, get started with the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx create-nx-workspace &lt;span class="nt"&gt;--preset&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;nest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will scaffold out a whole new Nx workspace, with a &lt;a href="https://nestjs.com/"&gt;Nest&lt;/a&gt; application already configured and ready to roll!&lt;/p&gt;

&lt;p&gt;Alternatively, if you already have an Nx workspace configured for your organization, you can add support for Nest (or even Express!) with the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;yarn add @nrwl/nest
yarn nx generate @nrwl/nest:application my-nest-application
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Hint - if a Nx frontend project already exists (either Angular or React), you can also include the &lt;code&gt;--frontendProject&lt;/code&gt; with the name of the project you wish to target. This flag will automatically set up a proxy configuration for that project, perfect for a microservice use case. 😉 &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And start plugging away at creating your Node app! &lt;/p&gt;

&lt;p&gt;Once some APIs have been made you can start your application with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;yarn nx serve my-nest-application
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Building Node Libraries (sharing is caring)
&lt;/h2&gt;

&lt;p&gt;Let's say that rather than build some API, you're working on an open source project that provides date functions. Nx + Node is perfect for this!&lt;/p&gt;

&lt;p&gt;Get started by creating your new Nx workspace with the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx create-nx-workspace &lt;span class="nt"&gt;--preset&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;oss awesome-dates
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;The &lt;code&gt;--preset=oss&lt;/code&gt; flag sets up the Nx workspace to have generated applications and libraries be placed into a &lt;code&gt;packages/&lt;/code&gt; folder. This is similar to how the Nx repo is structured. 😄&lt;/p&gt;

&lt;p&gt;We also named our new project &lt;code&gt;awesome-dates&lt;/code&gt; 🗓&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;After your workspace has been generated, we should add the &lt;code&gt;@nrwl/node&lt;/code&gt; package.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;yarn add @nrwl/node
yarn nx generate @nrwl/node:library add-months &lt;span class="nt"&gt;--publishable&lt;/span&gt; &lt;span class="nt"&gt;--importPath&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;@awesome-dates/add-months
yarn nx generate @nrwl/node:library add-days &lt;span class="nt"&gt;--publishable&lt;/span&gt; &lt;span class="nt"&gt;--importPath&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;@awesome-dates/add-days
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;We generated a couple of Node libraries so that when we publish these libraries they're independent, small and scalable.&lt;/p&gt;

&lt;p&gt;We also provided the &lt;code&gt;--publishable&lt;/code&gt; and &lt;code&gt;--importPath&lt;/code&gt; flags so that we can use the &lt;code&gt;nx build&lt;/code&gt; command for these libraries. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Hammer away at those date functions, add your tests, build and publish!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;yarn nx run-many &lt;span class="nt"&gt;--target&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;test&lt;/span&gt; &lt;span class="nt"&gt;--all&lt;/span&gt;
yarn nx run-many &lt;span class="nt"&gt;--target&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;build &lt;span class="nt"&gt;--all&lt;/span&gt;
yarn publish ./dist/add-months
yarn publish ./dist/add-days
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🎉&lt;/p&gt;

&lt;h2&gt;
  
  
  Building Nx Plugins (Nx is taking over the world)
&lt;/h2&gt;

&lt;p&gt;You've been playing with Nx for some time, and you always seem to be duplicating some build steps, or some templates, and you think, "These build steps and templates can be shared with everyone who does this!" &lt;/p&gt;

&lt;p&gt;Perfect! Nx can help you with this! &lt;/p&gt;

&lt;p&gt;Nx Plugins are built on top of the Node builder, and we can quick start a Nx Plugin workspace with the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx create-nx-plugin awesome-nx-plugins
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;This command functions similarly with &lt;code&gt;create-nx-workspace&lt;/code&gt;, but the command will scaffold out a folder directory thats more suitable for plugins, which include e2es. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You can read a full walk through of &lt;a href="https://nx.dev/latest/node/plugins/nx-plugin/overview"&gt;creating Nx Plugins on the nx.dev site&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;With the above examples, you can &lt;strong&gt;&lt;a href="https://nx.dev/latest/node/getting-started/why-nx"&gt;start building your Node focused project easily with Nx&lt;/a&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;These examples are just the beginning. Be on lookout for more in depth guides which will focus on:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Building, serving, and publishing microservices&lt;/li&gt;
&lt;li&gt;Building and publishing CLIs&lt;/li&gt;
&lt;li&gt;Deploying serverless functions&lt;/li&gt;
&lt;li&gt;and more!&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>nx</category>
      <category>node</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
