What does a node.js web application’s setup look like on a real production server?

Being new to node js magic world, i’m wondering how does a web application’s setup look like on a real production server?
So far all tutorials, create the js file that is started from a console…and that’s it.
Anyone has created a real world web app that uses node js in the back end? Can you please describe how is it setup, and how reliable this infrastructure is ? I’m coming from the asp.net and php world that require heavy web servers…and can’t have a clear idea about node stuff.

2

I work on a node.js web application that is not yet in production, but we do run a development server setup similarly to how I would setup production.

It’s a Linux server (CentOS specifically, but any distro would do) with a service account dedicated for running the web app. Deployment is as simple as SCP’ing the tarball file up to the server and running:

$ npm stop <app name>
$ npm install ./<app name>-<version>.tgz
$ npm start <app name>

npm allows for life cycle scripts to be setup via package.json which is how npm stop and npm start are implemented. By default, npm start calls node server.js if there is a server.js in the top-level directory. You can define your own start script easily via package.json.

We use the daemon module when starting up via npm start in order to run the app in the background, totally disconnected, with output redirected to a log file. Starting directly via server.js, however, skips the daemon step so I have an interactive terminal in development.

Since we use npm for packaging and installation, the code ends up living under $HOME/node_modules/. And again, this runs under a dedicated user account, so I know exactly what modules are and are not available at runtime.

In order to leverage multiple CPU’s, the server.js script will fork a worker (via the cluster module) for each CPU and monitor them for death. If a worker dies, the master process restarts it. There are modules out there to kick off your app and auto-restart if it dies, however, given that our master does no work except for baby sitting the workers, I don’t bother watching the master. The game of “who watches the watchers” could go on infinitely.

When going to production, there are only three more elements to build out, which we have not done yet:

  1. Load balancing, which is not part of the app itself and has nothing to do with node.js
  2. An init script to start and stop the service when the server box is rebooted.
  3. When shutting down the service to install a new release, we need to remove it from the load balancer pool and then put it back in.

Use a Platform as a Service.

I’ve successfully deployed to Heroku and Jit.su. Nodester seems cool, and I’ve used Azure for .NET things and if Node.js is equally good then that is a good option as well.

If you want to host a node app on your own server you could just run node app.js on your server.

2

I have came across the similar asignment where I asked to implement or create three different modules.

  1. Web application
  2. REST application
  3. Node

All my web application requests are pointing to REST module which is purely Spring web service implementation. This is before node.js coming in to picture. Later I asked to add node layer in between web and REST module so that all my web applications request should route through node module and node will hand it over to REST module and vice versa. This is because looking at the business need and some specific requirement.

So my web application is having all static html implementation which are calling node.js module through jquery ajax call and on success html dom elements are filled up with some values.

Lets take an example
I have a button click event on which jquery ajax call should be called to node application. For this node application must be in running state. To run node.js application use following command.

$ node index.js

Where index.js is my main starting point for node module which has some url
e.g. getContactDetails

$(document).on("click", "#btnClick", function(event) {
      jQuery.ajax({ 
type : 'POST', 
url : "http://nodeserver:port/appurl", 
dataType :"json", 
data : JSON.stringify(someJSON), 
contentType : "application/json;charset=utf-8", 
success : function(data) {
    /*Some code*/},
error :function(data) {
    /*Some code*/}
    });
    });

Inside node I am giving call to REST module like below

requestObj({
            url : restUrl,
            method : "POST",
            headers : { "Content-Type" : "application/json","pubKey":composeJSON},
            body : JSON.stringify(tmp.body)
        },
        function (error, res, body) {
            indexresponseBody = JSON.stringify(JSON.parse(body).message);
        }
    );
    res.writeHead(200, {'content-type':'text/html'});
    res.write("data",indexresponseBody);
    res.end();

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật