Tuesday, September 8, 2015

NodeJS Server Uptime

In NodeJS, everything is handled by a single javascript thread. So if an error get occurred, the server will stop.But this won't happen in traditional web servers. Because, in traditional web servers, there is a thread pool to handle requests. For each request, a thread will be assigned. If there is an error, that particular thread will discarded and new thread will be allocated.
In the following code, there are some invalid code.
In the first request, error get occurred and then server won't process any more requests.
Using forever we can automatically restart NodeJS server. First install forever like below.
Now, run above code using following command.
In the first client request server will crash. But forever will restart the server again. Forever is not a better way to handle errors in NodeJS application. But this is useful as a back for the unexpected.

Measuring Executing Time In Javascript

In this post I will explain how to use console.time() for measuring time in javascript program.
We can write a function like below to verify the execution time for a particular program.
But using console.time(), we can write our code more clearly like below.

Monday, August 3, 2015

Using Method Call In Meteor

In my last post I showed how to use publish/subscribe in meteor and how to allow access for specific  data in our database. But still every user have Create/Update/Delete privileges. Now we should remove those client side privilege and do those operations only in server side. To do that we can use meteor methods. The all the database functionalities can be execute only in server side.
First we will remove insecure package from meteor.
Run the application and try to create a student. You will get Access Denied Error.
Methods allow us to call database create/update/delete operation without executing that code in client side. First we will implement method for create student. Add studentMethods.js file into server folder and content should be like below.
Then modify studentCreate.js file like below. Then student create should work fine.
Download source code from github.