How to show all window service in listview


In this post will show about how to get list all of window server to display or show in ListView control in C# programming.

Source code below show about get all all window service to display in ListView
using System.ServiceProcess;

ServiceController[] services = ServiceController.GetServices();
foreach (ServiceController service in services)
{
   ListViewItem item = new ListViewItem();    
   item.Text = service.ServiceName;
   item.SubItems.Add(service.DisplayName);
   item.SubItems.Add(service.Status.ToString());
   this.listViewShowService.Items.Add(item);
}

Source code below show about get window server by specific service name and checking its status
using System.ServiceProcess;

ServiceController service = new ServiceController("ServiceName");
if (service.Status == ServiceControllerStatus.Running)
{
     // Process running
}
else if (service.Status == ServiceControllerStatus.Stopped)
{
    // Process stoped
}
else if (service.Status == ServiceControllerStatus.Paused)
{
    // Process paused
}



Node.js with File System


In this post we will show about show to Node.js work with file system how to open, read, write and append text. Node.js includes fs module to access physical file system. The fs module is responsible for all the asynchronous or synchronous file I/O operations.
1. Read File
To read text from this use method fs.readFileSync()
var fs = require('fs');
var data = fs.readFileSync('file.txt', 'utf8');
console.log(data);
2. Write File
Use fs.writeFile() method to write data to a file. If file already exists then it overwrites the existing content otherwise it creates a new file and writes data into it.
var fs = require('fs');
fs.writeFile('test.txt', 'Hello World!', function (err) { 
 console.log('Write operation complete.');
});
3. Append Text to File
use fs.appendFile() method to append the content to an existing file.
var fs = require('fs');
fs.appendFile('test.txt', 'text will be append', function (err) { 
 console.log('Append operation complete.');
});

Starting with Node.js

node.js
In this post will be show about introduction and starting with Node.js. This post will be help you to understanding from basic Node.js to advance.

 1. What is Node.js?
  • Node.js is JavaScript run-time build on Chrome's V8 JavaScript Engin.
  • Node.js is use event-driven, non-blocking/IO model that make it lightweight and efficient and cross-platform run time environment.
  • Node.js was developed by Ryan Dahl in 2009.
2. Advantage of Node.js?
  • Open-source framework under MIT license (MIT license is a free software license originating at the Massachusette Institute of Technology.
  • Use JavaScript to build entire server side application.
  • Lightweight framework that include bare minimum module. Other module can be include as per the need of an application.
  • Synchronize by default So It perform faster that other framework.
  • cross-platform framework that can run on Window, Mac and Linux.
3. Installing Node.js on Window
  1. Download Node.js from website https://nodejs.org/en 
  2. After download is finis please double-click on it to starting installation.
  3. After complete installation please find Node.js command prompt and open it to verify node.js installation as bellow:
  $ node --version
4. Starting with First Code
To starting write code with Node.js please follow as bellow:
1. Create folder project (ex: nodeproject)
2. Create file javascript that put name main.js and write code as bellow
 
   /* Hello, World! program in node.js */
   console.log("Hello, World!")

3. Open Node.js command prompt and browse to folder project and then type command as bellow
  $ node main.js


Creating web server with Node.js


In this post we will show about how to create node.js server with http module.http module includes classes, methods and events to create Node.js http server. Before starting create server in node.js let us to see part of Node.js application. Node.js include three type of module.
  1. Core Module
  2. Local Module
  3. Third party Module
To create server in node.js please see code bellow:
var http = require("http");
http.createServer(function (request, response) {
   response.writeHead(200, {'Content-Type': 'text/plain'});
   response.end('Hello World\n');
}).listen(8081);
console.log('Server running at http://127.0.0.1:8081/');

  • var http = require("http") is used to import core module http of node.js for create server.
  • http.createServer() is used to create server that listen with port 8081.
Now execute the main.js to start server as bellow

Next open browser and type localhost:8081 or 127.0.0.1:8081