Start Node.js Development in Visual Studio 2015

Node is a platform for building fast and scalable server applications using JavaScript.

Install Node for your platform:

visual studio

One can download the Community Edition since it is free for study.

After installation, now create one new project in Visual Studio.

JavaScript

You can see the separate JavaScript language tab.

Now using the search Nugget package for nodejs.

After completion of the installation restart Visual Studio and select the JavaScript tab. You will be able to see the following projects.

completion of the installation

Node.js Express

Express is a minimal and flexible Node.js web application framework that provides a robust set of features for web and mobile applications.

If you need more information on Express then please find the following link:

We can create a blank Node.js application and add the express script or we can create a new application using Node.js Express.

For this time I am creating a Basic Node.js Express application.

creating Basic Node

app

We will go through some new terms.

  1. npm: npm is a NodeJS package manager. As its name implies, you can use it to install node programs. Also, if you use it in development, it makes it easier to specify and link dependencies. If anyone needs to add new dependencies to the project then he can add those using npm.

    The way to add is to right-click on npm and then do as in the following:

    way of adding

    You can install packages using “Install new npm packages”.

    To get a better understanding of npm packages please go through https://www.npmjs.com/.

  2. Express: As I said earlier, this is the web framework for node.js.

  3. Jade: jade is a template engine for node.js and the default rendering engine for the express web framework. We can say it is an alternative to HTML.

    Example

    extends layout.

    block content.

    h1= title
    p Welcome to #{title}


    If you need more details on Jade then please go through http://jade-lang.com/.

  4. App.js: This is the default JavaScript file.
    1. http.createServer(app).listen(app.get('port'), function () {  
    2.    console.log('Express server listening on port ' + app.get('port'));  
    3. });  
  5. package.json: The package.json file is normally located at the root directory of a Node.js project. The name field should explain itself. This is the name of your project. The version field is used by npm to ensure the right version of the package is being installed.

  6. Routes: Routing refers to determining how an application responds to a client request to a specific endpoint, that is a URI (or path) and a specific HTTP request method (GET, POST, and so on). Each route can have one or more handler functions, that is / are executed when the route is matched. Route definition takes the following structure app.METHOD(PATH, HANDLER), where the app is an instance of express, METHOD is an HTTP request method, PATH is a path on the server and HANDLER is the function executed when the route is matched.

    Example
    1. exports.index = function (req, res) {  
    2.    res.render('index', { title: 'Express' });  
    3. };  
    To understand more on routes please go through http://expressjs.com/guide/routing.html.

code

When you start the application then:

  1. Server starts locally:

    *Server start

    The following is the page as shown in a browser:

    page get shown in browser

Up Next
    Ebook Download
    View all
    Learn
    View all