JavaScript

Node.js 9.x.x and npm 6.x.x – “npm audit” to identify and fix security vulnerabilities in dependencies

June 3, 2018 JavaScript, Javascript Development, Modern Web Development, Node.js, NPM, OpenSource, Package Manager, Tech Newz, TypeScript, Web No comments

nodejs-npm

It has been a while I have been reading about the major changes that areintroduced in Node.js 9.x.x / NPM 6.x.x and myself faced by Node.js application going to a toss after I upgraded to Node.js 9.x.x, as I always keep Node.js up to date in my development environment.

I use NVM(Node Virtual Manager) to switch between different version of Node.js and I love the flexiblity NVM provides. So I was able to quickly switch back to 8.x.x version, when I figured out this change.

But npm packgage downgrade did not work using “npm install –g [email protected] due to old traces of 6.x.x   I had to clean up my npm cache and do npm install again.

Introduction – The “npm audit” command:

Recently with 6.0.0 NPM team has introduced many improvements such as :

a.) Provide protection against insecure code into the workflow during your npm install . When a user downloads code from the npm Registry, npm will review the request against the Node Security Platform database and return a warning if the code contains a vulnerability.

b.) Package signing for publishers.   npm-signature field will allow users of npm packages to verify the integrity of the package regardless of the tools they use to retrieve it or the registry from which they download it.

c.) Security auditing capability (which I am covering in this article).

The audit capability, which provides an ability to perform a security audit  on your project and dependency components.  To simplify it provides a moment-in-time security review of your project’s dependency tree.

  • It will scan your project for any vulnerabilities. 
  • You can choose the option to automatically install the compatible updates vulnerable dependencies.
  • Audit reports contain information about security vulnerabilities in your dependencies.
  • This report also contains necessary steps to be taken to fixe these vulnerability. For example, by running an npm install <package>@new-version.
  • It would work very well with your private/enterprise registries such as artifactory etc. 
  • It  will allow the developer to recursively analyze trees of dependent code to identify specifically what’s insecure.

The audit command submits a description of the dependencies configured in your project to your default registry and asks for a report of known vulnerabilities.

Quick Insight on the new commands:

  • npm audit      – Scan your project for vulnerabilities and just show the details, without fixing anything.
  • npm audit [—json]      – To provide report in Json format.
  • npm audit fix   – to scan and fix all vulnerabilities
  • npm audit fix –only=prod     – to skip updating devDependecies
  • npm audit fix –force  – will install semver-major updates to all top level dependencies.
  • npm audit fix –dry-run –json   – to do a dry run on the fixes and provide you a report.

NB: Npm audit fix runs a full  npm install under the hood, all configs that apply to the “npm audit fix”  will also apply to npm install.

References:

[NPM Tip] Error: self signed certificate in certificate chain

May 10, 2018 JavaScript, Javascript Development, OpenSource, TypeScript, Web, Web Development No comments

As a developer, if you are behind a corporate proxy that assigns an intermediatory self signed SSL certificate to every request to provide secure content filtering as part of cybersecurity measures, I am sure you might have gone through the pain to get it working when working with NodeJS.

if you have Admin access to your windows machine, you could simply try the following fix:

    • Simply Add an Environment Variable
Environment Variable Name: NODE_TLS_REJECT_UNAUTHORIZED, Value: 0

image

image

Hope that solves your problem.

[NPM Tip] Rewriting the default protocol for GitHub package references

May 9, 2018 JavaScript, Javascript Development, OpenSource, TypeScript, Web, Web Development No comments

Some times as a Modern Web Developer you will face some “npm install” as some of the packages would be referring to git/ssh protocol to reference private packages from Git Hub.

This would fail when you are behind a corporate proxy.

Rewriting the default protocol for GitHub, run the following snippet in your command line snippets:

git config --global url."https://github.com/".insteadOf [email protected]
git config --global url."https://".insteadOf git://

Setting up Local NPM repository to Speedup Dev/CI Builds

April 29, 2018 Emerging Technologies, JavaScript, JavaScript, Modern Web Development, TypeScript, Web No comments , , ,

As a modern day JavaScript developer working with Node.js and NPM, it has been always any developer’s case to clean up local node modules sometimes when local build is broken. It is a tedious tasks to cleanup %appData%\npm-cache  to do a fresh install of all the modules again. Depending on the number of modules your project have, you will get stuck up for few minutes to hours to complete npm module installation depending on your Internet bandwidth.

Another scenario we can think of it on a build server or CI server, where we need to cleanup the entire modules during each build process, and ‘npm install’ would be like a fresh start, would take longer time to have your build complete.

What if we have a simple way of caching these packages locally, so that we do not have to download again from Internet every-time.  I will help you with a simple solution, that once setup will resolve some of these problems effectively.

Introducing Local-NPM


local-npm is a Node server that acts as a local npm registry. It serves modules, caches them, and updates them whenever they change. Basically it’s a local mirror, but without having to replicate the entire npm registry.

This allows your npm install commands to (mostly) work off-line. Also, your NPM modules  get faster and faster over time, as commonly-installed modules are aggressively cached.

local-npm acts as a proxy between you and the main npm registry. You run npm install commands like normal, but under the hood, all requests are sent through the local server.

 

Getting Started with Local-NPM:

Step 1: Install the module ‘local-npm’

$ npm install –g local-npm

Step 2: launch local-npm  and this will start the local npm server
$ local-npm

This will start the local npm server at localhost:5080.
http://127.0.0.1:5080

PS: Please note that, this step would take some time as this module tried to replicate the entire NPM repository remote skimdb to the local couchdb instance for efficient caching. But it will not eat up your disk space, as it caches modules based on usage only, it will not replicate the entire NPM repository.

Step 3: Validate the local-NPM registry

There is a basic NPMJS like UI to browse through local packages which can be accessed through.

http://localhost:5080/_browse.

Step 4: Then set npm to point to the local server:

$ npm set registry http://127.0.0.1:5080

Step 5: run  “npm install” of your modules and you can see that local-NPM caches these modules that you regularly use.

Incase, to switch back to default NPMJS registry, you can do:

$ npm set registry https://registry.npmjs.org

How it works?

npm is built on top of Apache CouchDB (a No-SQL db), so local-npm works by replicating the full “skimdb” database to a local PouchDB Server.

You can inspect the running database at http://127.0.0.1:16984/_utils.

References

To understand more on local-NPM and documentation visit the module repository in [email protected]https://github.com/local-npm/local-npm

Getting Started with Azure Functions App

June 25, 2017 .NET, .NET Framework, App Service, Azure, C#.NET, Emerging Technologies, Functions App, JavaScript, Microsoft, Windows Azure Development, Windowz Azure No comments

In my previous article I gave you an overview of Azure Functions and discussed about the benefits of the Azure Functions. With this session I will cover you with necessary steps to create an initial basic functions app.

Getting Started:

Login to Azure Portal, you will see Function Apps section in the left menu. This is where all your Function Apps will be listed, once you login.

imageimage

Let us start by creating a new Function app. Type Functions

image

Select Function App from Web + Mobile category, and Click on Create Button.

Fill In details:

  1. App Name,
  2. Select Subscription
  3. Select Resource Group (new if you want to create new resource group) or select existing
  4. Select Hosting Plan
  5. Specify Storage
  6. Click on Create

imageimage

You will see deployment in progress message.

imageimage

image

Once you explore further selecting the Function App instance you will be able view the URL and left side  menu you will see the options to configure:

  1. Functions
  2. Proxies (Preview Feature)
  3. Slots (Preview Feature)

image

Getting Started – create first Function App

Now since we have new instance ready. Let us create our first Function.

We have to choose by :

1.)  Choose a scenario:

  1. Webhook + API
  2. Time
  3. Data Processing

2.)  Choose a language:

  1. JavaScript
  2. CSharp
  3. FSharp
  4. For PowerShell, Python and Batch processing, you create your own custom function

image

For the demo sake I am creating a Timer Scenario and selected CSharp as the language.

image

I created a simple trigger code  and Click on Save and Run

image

Job has completed within speculated delay we put through on the Thread.Sleep:

image

Code Sample:

<br />
using System;<br />
using System.Threading;</p>
<p>public static void Run(TimerInfo myTimer, TraceWriter log)<br />
{<br />
    log.Info($"C# Timer trigger function executing at: {DateTime.Now}");</p>
<p>    RunTest(log);</p>
<p>    log.Info($"C# Timer trigger function completed at: {DateTime.Now}");<br />
}</p>
<p>public static void RunTest(TraceWriter log)<br />
{<br />
    for(int i=0; i&lt; 100; i++)<br />
    {<br />
       log.Info($"C# Timer trigger function executing at thread: {i}"); </p>
<p>        Thread.Sleep(1000);</p>
<p>        log.Info($"C# Timer trigger function completed at thread: {i}");<br />
    }<br />
}<br />

Using the Functions –> Integrate section we can configure Input, Output parameters and Schedule Timers, to make it available as a WebAPI methods. You can call this functional logic from another application to invoke as a web API call by passing necessary inputs, to start another functional process.

One example for this scenario would be to invoke a Database record archival  call after completion of an order. This is will be applicable in case we choose the scenario WebHook + API during the creation of your functional logic.

image

That’s all for now for this topic.  I will cover more details about WebHook + API in next series.

Please share your comments and rate this article to help me understand areas of improvement.

Additional Refs:

Visual Studio 2015 Update 3 – Download

June 27, 2016 .NET, .NET Core 1.0, .NET Framework, .NET Framework 4.5, .NET Framework 4.5.2, .NET Framework 4.6, ASP.NET, ASP.NET 5.0, ASP.NET Core 1.0, ASP.NET MVC, C#.NET, Community, JavaScript, Microsoft, MSDN, Trial Downloads, Updates, Visual Studio 2015, Visual Studio Code, Visual Studio SDK, VisualStudio, VS2015, WCF, Web API v2.0, Windows, Windows 10, Windows 7, Windows 8, Windows 8.1, Windows Azure, Windows Azure Development, Windows Phone Development, Windows Phone SDK, Windows Store Development, WPF, WWF, XAML No comments

Today Microsoft has released Update 3 for Visual Studio 2015. Visual Studio 2015 Update 3 includes a variety of capability improvements and bug fixes. To find out what’s new, see the Visual Studio 2015 Update 3 Release Notes. For a list of fixed bugs and known issues, see the Visual Studio 2015 Update 3 MSDN Article.

Download:
Visual Studio Community 2015 with Update 3 – Web Installer –  ISO
Visual Studio Enterprise 2015 with Update 3 – Web Install –  ISO
Visual Studio Professional 2015 with Update 3 – Web Installer –  ISO
Visual Studio 2015 Update 3 – Web InstallerISO
Visual Studio Team Foundation Server 2015 with Update 3 – Web Installer –  ISO
Visual Studio Test Professional 2015 – Web InstallerISO
Visual Studio Express 2015 for Windows 10 – here
Visual Studio Express 2015 for Web – here
Visual Studio Express 2015 for Desktop – here