SHASHANGKA SHEKHAR'S BLOG

Author, TechWriter

Package Manager NodeJS

Hits: 74

In this post we are going to explore how to manage front-end dependencies with NodeJS sample web application using Visual Studio 2017.

Topics:

  1. Install NPM Task Runner for VS 2015/2017
  2. Install Bower – Manage front-end dependencies
  3. Install Gulp – Front-end build tools

In our previous post we have learnt how to start with NodeJS. Get review once again by following the link : http://shashangka.com/2018/01/20/startup-nodejs/

You can start with a new sample nodejs application to follow the instruction, in this case I have started with previous sample app.

NPM Task Runner

Go to Visual Studio Marketplace for NPM Task Runner extension download it. Close visual studio then open the file with .vsix type to install NPM Task Runner.

After successful installation open VS2017 then from top menu Go to > View > Other Windows > Task Runner Explorer

This will open below window.

Install Bower & Gulp

Next we are going to install both, we need to add new dependencies in package.json

Finally Package.json

Now update NPM packages.

We can also install packages using Command prompt by right click on project.

For Bower:

For Gulp:

As we can see from below image the packages are listed.

Now right click on project to open command prompt to initialize Bower. In command prompt write command ‘bower init’, after configuration process it’ll generate a sample code snippet for bower.json file.

bower.json

We will add some dependencies in bower.json file

Finally build the application to restore the dependencies to our solution like below. Click on show all file to view bower component folder.

Now add a js file by naming it ‘gulpfile’, to copy the required component to public folder which we are going to reference in our layout page. Open the file copy paste below code snippet.

Once again let’s go to> View > Other Windows > Task Runner Explorer click on refresh button to see the listed task to run.

Right click on a task then click Run,

this will copy our library files to desired application location to reference it in our layout page like below screenshot.

Finally another thing to modify in our node server to serving static files.

Here express.static middleware function to serve static files like images, css, & JavaScript files.

Let’s add angular attribute in body tag ‘body ng-app’, then add ‘ng-model’ to join string using angular expression.

OutPut:

Source Code: I’ve uploaded the full source code to download/clone @github, Hope this will help 🙂

2 Comments

Post a comment