Diadem Technologies Hosting Knowledgebase

Running node.js on Localhost

Article ID: 1265
Last updated: 26 Jul, 2020
  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.

This article was:  
Report an issue
Article ID: 1265
Last updated: 26 Jul, 2020
Revision: 5
Views: 31
Comments: 0