NodeJS

Node.js_Logo

Node.js is built on Google Chrome’s JavaScript runtime. It helps you build scalable network applications. With event-driven, non-blocking I/O model, it offers efficiency which is ideal for data-intensive real-time applications that run across distributed devices. Node.js is a platform. It works on the server-side. Node.js can function with other front-end toolset(s) such as AngularJS.

  • Suitable for
    • Rapid development where the applications need to undergo quick and frequent changes.
    • Latency sensitive – Ideal for applications where page load time matters.
    • Enterprises which are looking to improve developer productivity – Using the package management system called NPM, it is possible with Node.js to merge web and backend teams into one unit.
  • Architecture
    • The architecture is MVC (Model-View-Controller). It can also support other patterns such as Model-View-Presenter or Actors.
  • Programming
    • Supports Event-driven, Object-oriented, Functional, Concurrency Oriented, Pub/Sub programming paradigms.
    • Offers support for Ruby, CoffeeScript and TypeScript Scripting languages.
    • Offers official IDE Support.

Things it does:

    • It Communicates communicates with databases, web-sockets, middle-ware etc.
    • It Serves serves web.

Getting Started

To begin with we need to install Node.js and npm. npm is a package manager for node and helps us in easily deploying modules for added functionality.Here is a cool guide on installing node and npm for windows.

  1. Install NodeJs from http://nodejs.org/
  2. Create project folder and setup the NodeJS project:  npm init

This will create package.json which contains project dependencies.

 

Folder structure

Our Node.js platform is broadly classified into the following folders:

  1. App Folder: Contains the models for data connections and api serving. Includes the files:
    1. SubjectViews.js: holds the data model. Specify specific queries (if any) and the collection name to fetch data from
    2. routes.js: Fetches data from the collection and serves it as an api
  2. Config Folder:
    1. DB.js: Contains the database information i.e. the address and the port to connect to
  3. node_modules folder: Contains various node modules which are installed to enhance functionality of the node server
  4. Public Folder: Will contain our html, javascript and css files. We will use these three to code our charts utilizing the visualization and aggregation libraries.
  5. package.json file: Contains a list of all the modules which need to be installed for the server to run
  6. server.js file: The file utilizes the node modules to initialize data fetch from mongoDB and host our webpages over the network.

The folder structure for our project will look like this:

folderstr.png (278×404)

 

Website

Source Code

  • anmolkoul/node-dc-mongo · GitHub

    node-dc-mongo – Source code for the project demonstrating data visualization using d3.js, dc.js, node.js and mongodb

    Source: github.com/anmolkoul/node-dc-mongo

 

References