Running node.js on Localhost

Running node.js on Localhost

  1. Install Node.js for your platform i.e Windows
  2. Type nodejs.org in your browsers address bar, or click the link  https://nodejs.org/en/download/
  3. Download the installer and run it.

  1. After finishing Installation open a command prompt and type :

These commands are universal for whatever OS you’ll be running. The former will create a new directory inside the directory you are currently in, mkdir = “make directory”. The latter will change into this newly created directory, cd = “change directory”.

  • mkdir myapp
  • cd myapp

Note : Npm is short for node package manager. This is where all node packages live. Packages can be viewed as bundles of code, like modules, which carry out a specific function. This functionality is what we as developers are utilizing. We use the application program interface, the API, provided for us by these modules.

  1. Install Express in the myapp directory (Express is a minimal and flexible Node.js web application framework that provides a robust set of features for web and…)
  • npm install express --save
  • npm install http-server
  1. Start your text editor of choice and create a file named app.js and type below mentioned code for testing and save it into your directory...here my application directory is C:\Users\Administrator\myapp.
var express = require('express');
var app = express();app.get('/', function (req, res) {
res.send('Hello World!');
});app.listen(8080, function () {
console.log('Example app listening on port 8080!');
});
  1. Run the app type the command node app.js in command prompt.
  2. After running the command, load http://localhost:8080/ in a browser to see the output. You should also see “Example app listening on port 8080!” get logged to the command line.

Note: If you want to change the directory of your application, simply create the folder as per your need run:npm install express --save command in command prompt in the directory where you will be keeping your application, this command will add the express framework which is used for running node js application.

Installing Window service

Interactively

> qckwinsvc
prompt: Service name: Hello
prompt: Service description: Greets the world
prompt: Node script path: C:\myapp\app.js
prompt: Should the service get started immediately? (y/n): y
Service installed.
Service started.

Non-interactively

> qckwinsvc --name "Hello" --description "Greets the world" --script "C:\myapp\app.js" --startImmediately
Service installed.
Service started.



    • Related Articles

    • Enable node.js with IIS

      Configuring IIS node.js with Windows Server 2012 Before proceeding further we need to install below mentioned application:- Download Node JS for Window (https://nodejs.org/en/download/). Now for Installing IIS node, search for IIS node on Web ...
    • Deploying node.js in Diadem Express Cloud

      we need to login to the Diadem EC control panel, once logged in we can created a new environment. as shown in the below given picture. I have deployed a basic node.js without any load balancing and sql server, in the above picture I have marked the ...
    • How to install Dependencies for Node.js application

      Install websocket modules for nodejs at Plesk server Step-01: Checking Node.js and npm version: 1. Login to server through SSH using root user. 2. The data directory of the Node.js application at plesk is /opt/plesk/node/<Node.js version>/* ...
    • How to enable Node.js Support in Plesk

      Install Node.js support at Plesk Onyx through updating the plesk Plesk Onyx offers Node.js support. Node.js is an open-source, cross-platform runtime environment for developing server-side Web applications. Step-01: Installation process 1. Login to ...
    • How to view usage statistics of any node from Diadem Express Cloud panel

      To view full usage statistics of any node from Express Cloud panel. 1. Login to your Diadem Express Cloud account using your login credentials. 2. Expand your environment and hover on the nodes where you want to see the statistics report icon. Now ...