📜 ⬆️ ⬇️

Deploying node.js applications


Deploying an application is always a critical point in the development cycle ... and never easy. If you use the services of hosting providers, then most likely you have already been provided with sufficient amenities of all services. In this article I will talk about the deployment of applications without creating a complex hosting infrastructure ...

To begin with we will decide on technology. We will use, of course, only what the development platform has provided us - node.js. A certain web service will run on the server, which will accept requests and do all the dirty work. On the client - command-line tool. Well, without him?

So, the service is installed as follows:
npm install -g node-deploy-server --unsafe-perm 


Customer, no more difficult ...
 npm install -g node-deploy-client 

')
Software is worth it, now it's time to tell how to configure it in order to make friends with the service together with the client.

Server Tuning.

The configuration file is named nodehosting.json and is located in the / etc folder for Linux systems and at the root of the module for Windows.
Full text configuration file
 { "port" : 15478, "username" : "admin", "password" : "admin", "applications" : { "application1" : { "path" : "../applications", "foreverConfig" : { "cwd" : "../applications/application1" }, "startProcess" : true } } } 



Application Setup:

Separately, I want to say about the installation of dependencies. It is performed using the npm install command in the root folder of the application. For example, this is ../applications/application1. Thus, if it is necessary to perform additional actions during deployment, it is enough to register them in the scripts.install field in package.json

Customize the client.

In the root folder of the application (next to package.json), you must put a file named .deploy with the following content:
 { "dev" : { "url" : "http://admin:admin@localhost:15478" }, "staging" : { "url" : "http://admin:admin@192.168.1.3:15478" } } 

Unlike the server here is not a lot - the very minimum to connect with the server. In the file, you can specify multiple configurations. Those. You can define several different servers for deployment, for example: dev, staging, production. The choice of a specific server is made by the client utility. The actual configuration name in the test case is dev and staging. A more detailed example can be viewed on github

Start the server.

We start the server on Linux
 service nodehosting start 

Do not forget to execute the chkconfig nodehosting on command if you want the service to start when the OS starts.

We start the server on Windows
 sc start nodehosting.exe 


Client launch

To deploy an application, go to its root folder and execute on the command line
 deploy dev 

The output of the command looks like this:


How it works?

The client part opens the package.json file and uses the "name" field as the name of the application (not at all strange). Next, it packs the root folder excluding the node_modules folder from the archive. The resulting archive is sent by POST via the http protocol to the address specified in the .deploy file. Well, on the server there are processes already described above.

Thanks

The project is young. So constructive criticism and suggestions are expected. Sources are hosted on github

If Che suddenly.

Tested on a couple of RedHat-based distributions, Debian 7.2 (wheezy) and Windows 7.

PS

From January 2014 a web interface is available. Thus, setting up applications has become much easier.

And…

Source: https://habr.com/ru/post/205730/


All Articles