<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic My First NPM Package in Alfresco Archive</title>
    <link>https://connect.hyland.com/t5/alfresco-archive/my-first-npm-package/m-p/160187#M114173</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE __default_attr="info" __jive_macro_name="alert" alert="info" class="jive_text_macro jive_macro_alert"&gt;&lt;SPAN style="color: #0f7198; background-color: #ffffff;"&gt;This is a personal blog post that is primarily intended for tracking my own learning rather than provided to the Alfresco Community for educational purposes. However if you find it useful, informative or have any comments on it then please comment below.&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;At the end of &lt;A _jive_internal="true" href="https://community.alfresco.com/people/ddraper/blog/2016/12/28/a-better-way-of-writing-and-testing-components" rel="nofollow noopener noreferrer"&gt;my last blog post&lt;/A&gt; I was looking at ways in which to write better components by abstracting as much non-browser specific code to utility modules. The idea of this was to improve testing so to minimize the amount of code that needed to be tested against multiple browsers. The side-effect of this approach means producing common capabilities that can be easily re-used against multiple web application frameworks such as &lt;A href="https://vuejs.org/" rel="nofollow noopener noreferrer"&gt;Vue.js&lt;/A&gt;, &lt;A href="https://facebook.github.io/react/" rel="nofollow noopener noreferrer"&gt;React&lt;/A&gt;, &lt;A href="https://angular.io/" rel="nofollow noopener noreferrer"&gt;Angular&lt;/A&gt;, etc.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As I developed my application I found myself pulling in more and more code and configuration that was already available in one of the many &lt;A href="https://github.com/vuejs/vue-cli" rel="nofollow noopener noreferrer"&gt;Vue.js CLI&lt;/A&gt; template projects. Most UI frameworks now come with a CLI that makes it easy to rapidly build out an application. I want to test out other frameworks so I thought it would make sense to abstract the core authentication and routing code into a separate project so that it could be imported into multiple different projects created using a CLI.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I followed some of the approach in &lt;A href="https://medium.com/@nohkachi/how-to-create-reusable-modules-in-express-4-x-by-using-events-for-loose-coupling-a63e89e44b22#.yfv2pa32f" rel="nofollow noopener noreferrer"&gt;this blog post&lt;/A&gt;&amp;nbsp;and then mostly following &lt;A href="https://medium.com/@jdaudier/how-to-create-and-publish-your-first-node-js-module-444e7585b738#.u9bogqmzw" rel="nofollow noopener noreferrer"&gt;these instructions&lt;/A&gt; on setting it up as &lt;A href="https://www.npmjs.com/package/alfresco-auth-router" rel="nofollow noopener noreferrer"&gt;an NPM package&lt;/A&gt;. Some useful information on testing the package prior to publication in described &lt;A href="http://podefr.tumblr.com/post/30488475488/locally-test-your-npm-modules-without-publishing" rel="nofollow noopener noreferrer"&gt;here&lt;/A&gt;. It was also necessary to follow &lt;A href="http://stackoverflow.com/questions/16631064/declare-multiple-module-exports-in-node-js" rel="nofollow noopener noreferrer"&gt;this information&lt;/A&gt;&amp;nbsp;in order to create a package with multiple exports.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The end result means that it is now possible to to install this new package with the following command:&lt;/P&gt;&lt;PRE class="language-none line-numbers"&gt;&lt;CODE&gt;npm install alfresco-auth-router --save-dev‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Or if you prefer &lt;A href="https://yarnpkg.com/" rel="nofollow noopener noreferrer"&gt;Yarn&lt;/A&gt;:&lt;/P&gt;&lt;PRE class="language-none line-numbers"&gt;&lt;CODE&gt;yarn add --dev alfresco-auth-router‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then it is just a simple case of setting up the &lt;A href="http://passportjs.org/" rel="nofollow noopener noreferrer"&gt;Passport.js&lt;/A&gt; and &lt;A href="https://expressjs.com/en/guide/routing.html" rel="nofollow noopener noreferrer"&gt;Express routing&lt;/A&gt; using the following code in the server.js file:&lt;/P&gt;&lt;PRE class="language-javascript line-numbers"&gt;&lt;CODE&gt;passport&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;use&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;alfrescoAuthRouter&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;passportStrategy&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;&lt;BR /&gt;passport&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;serializeUser&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;alfrescoAuthRouter&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;serializeUser&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;&lt;BR /&gt;passport&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;deserializeUser&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;alfrescoAuthRouter&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;deserializeUser&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;&lt;BR /&gt;server&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;use&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'/auth'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; alfrescoAuthRouter&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;authRoutes&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;passport&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;&lt;BR /&gt;server&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;use&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'/proxy'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; alfrescoAuthRouter&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;apiRoutes&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;‍‍‍‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This should make it much simpler to test out lots of different UI frameworks on Node.js against REST APIs provided by an Alfresco Repository. You can view this in &lt;A href="https://github.com/draperd/AlfrescoNodeJS" rel="nofollow noopener noreferrer"&gt;my project&lt;/A&gt; by checking out &lt;A href="https://github.com/draperd/AlfrescoNodeJS/releases/tag/Blog9" rel="nofollow noopener noreferrer"&gt;this tag&lt;/A&gt;.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 28 Dec 2016 17:16:20 GMT</pubDate>
    <dc:creator>ddraper</dc:creator>
    <dc:date>2016-12-28T17:16:20Z</dc:date>
    <item>
      <title>My First NPM Package</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/my-first-npm-package/m-p/160187#M114173</link>
      <description>This is a personal blog post that is primarily intended for tracking my own learning rather than provided to the Alfresco Community for educational purposes. However if you find it useful, informative or have any comments on it then please comment below.At the end of my last blog post I was looking</description>
      <pubDate>Wed, 28 Dec 2016 17:16:20 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/my-first-npm-package/m-p/160187#M114173</guid>
      <dc:creator>ddraper</dc:creator>
      <dc:date>2016-12-28T17:16:20Z</dc:date>
    </item>
  </channel>
</rss>

