Full Trust European Hosting

BLOG about Full Trust Hosting and Its Technology - Dedicated to European Windows Hosting Customer

Node.js Hosting Russia - HostForLIFE.eu :: How to Clustered HTTP Server in Node.js ?

clock February 24, 2015 07:39 by author Peter

In this short article, let me tell you about How to Clustered HTTP Server in Node.js. Now this is the code that I ued to clustere the HTTP Server:

function () {
    'use strict';
        var cluster = require('cluster'),
        http = require('http'),
        os = require('os'),       
        /*
         * ClusterServer object
         *
         * We start multi-threaded server instances by passing the server object
         * to ClusterServer.start(server, port).
         *
         * Servers are automatically started with a number of threads equivalent
         * to the number of CPUs reported by the os module.
         */
        ClusterServer = {
            name: 'ClusterServer',           
            cpus: os.cpus().length,           
            autoRestart: true, // Restart threads on death?
                        start: function (server, port) {
                var me = this,
                    i;                
                if (cluster.isMaster) { // fork worker threads
                    for (i = 0; i < me.cpus; i += 1) {
                        console.log(me.name + ': starting worker thread #' + i);
                        cluster.fork();
                    }                   
                    cluster.on('death', function (worker) {
                        console.log(me.name + ': worker ' + worker.pid + ' died.');
                        if (me.autoRestart) {
                            console.log(me.name + ': Restarting worker thread...');
                            cluster.fork();
                        }
                    });
                } else {
                    server.listen(port);
                }
            }
       },       
        /*
         * Simple example HelloWorld HTTP server
         *
         * Repsonds to any request with a plain txt "Hello World!" message.
         *
         * You can replace this with much more complex processing, naturally.
         */
        helloWorldServer = http.createServer(function (request, response) {
            response.writeHead(200, {
                'Content-type': 'text/plain'
            });
                        response.end('Hello World!');
            console.log('helloWorldServer: Served a hello!');
        });   
    ClusterServer.name = 'helloWorldServer'; // rename ClusterServer instance    ClusterServer.start(helloWorldServer, 8081); // Start it up!
}());

I hope it works for you!

HostForLIFE.eu Node.js Hosting

HostForLIFE.eu is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes. We have customers from around the globe, spread across every continent. We serve the hosting needs of the business and professional, government and nonprofit, entertainment and personal use market segments.



AngularJS Hosting - HostForLIFE.eu :: How to Create Alert Box with AngularJS?

clock February 10, 2015 17:14 by author Peter

In this short tutorial, I will show you how to create an alert box using AngularJS. There is the difference between JavaScript and AngularJS. In AngularJS "$window" is need to referring to global Window Objects. If you want to show the alert in Angular then you need to pass it as $window.alert. First step is you need to add an external Angular.js file to your app. You need to visit the AngularJS website. After downloading the external file, you should add the following code to the Head section of your application.

 

 <head runat="server">
    <script src="angular.min.js"></script>
    <title></title>
</head>

Next step, I will create a function and write this function in the head section of your apps:
<script>
        function greet($window, $scope) {
            $scope.hello = function () {
                $window.alert('Hi!! ' + $scope.name);
            }
        }
</script>

We created a function named "greet", in $scope function and $window are passed as objects as a result of scope is used to pass a value to the controller and as you recognize we are going to show an alert window. that's why $window is used.

An alert is used but have $window before it, during this alert the message "Hi!!" are displayed at the side of some value that will be passed through a TextBox. This will be done using the $scope.name. Now you'll be thinking that I have neither declared name anyplace nor provided an initial value to the scope, you'll pass the initial value before this hello function however that may solely help to point out some text by default and nothing much more than that.

Now write this code in the body section:
  <body>
    <div ng-controller="greet">
      Name: <input ng-model="name" type="text"/>
      <button ng-click="greet()">Greet</button>
    </div>
  </body>

Here first I have applied a controller to a div, then an input tag is used in which "name" is applied through the ng-model, thus no matter is entered into the TextBox are shown within the alert box on the click of a button. The button click is sure to greet using the ng-click(). currently our work on this application is completed and it's complete code is as follows:
<head runat="server">
    <script src="angular.min.js"></script>
    <title></title>
    <script>
        function greet($window, $scope) {
            $scope.hello = function () {
                $window.alert('Hi!! ' + $scope.name);
            }
        }
    </script>
</head>
    <body>
    <div ng-controller="greet">
      Name: <input ng-model="name" type="text"/>
      <button ng-click="greet()">Greet</button>
    </div>
  </body>
</html>

On running the application you will see a TextBox and a Button.

If now I click on the Button then an Alert message will be shown but in the alert box "Hello Undefined" will be shown because nothing is provided through the TextBox and no initial value was passed through the $scope.

HostForLIFE.eu AngularJS Hosting
HostForLIFE.eu is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes. We have customers from around the globe, spread across every continent. We serve the hosting needs of the business and professional, government and nonprofit, entertainment and personal use market segments.



About HostForLIFE

HostForLIFE is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes.

We have offered the latest Windows 2019 Hosting, ASP.NET 5 Hosting, ASP.NET MVC 6 Hosting and SQL 2019 Hosting.


Tag cloud

Sign in