Skip to content

Deploying Snapp

Adrian Hintze edited this page May 5, 2017 · 18 revisions

Once you have built Snapp the next step is to deploy it.

TL;DR

  • Copy the entire build directory wherever you want to have Snapp running
  • Put a copy of the project's package.json next to it
  • Make sure that both node & npm are installed
  • Install production packages: npm install --only=production
  • Run the app*: node build/snapp/Snapp.js
  • The application is now listening on port 80 and accessible through a browser

* It's probably better to use a more robust method like forever, a windows service, etc.

  1. Gather all relevant files
  2. Putting files in place
  3. Installing Node.js & npm
  4. Installing production dependencies
  5. Configuring Snapp
  6. Launching Snapp

1. Gather all relevant files

If you have downloaded the built application instead of building it yourself just go to the next step.

After building the application you could run it right in that directory, but it is recommended to move the built application to a different directory (or machine).

You will need to copy the following files and folders from your project root directory:

build/
package.json

2. Putting files in place

Put the build directory and the package.json into whatever directory you want the application to be running in. It should look like this:

./
├── build/
└── package.json

3. Installing Node.js & npm

If you are deploying on the same machine where you built Snapp yo can skip to the next step.

If not, you will need to install them on the new machine also. A bit more information about the process is found here.

4. Installing production dependencies

The project depends on some external packages to work properly. We will need to install them by using the following npm command (that's also the reason why we needed to copy the package.json file):

npm install --only=production

After the process is finished we should have the following directory structure:

./
├── build/
├── node_modules/
└── package.json

5. Configuring Snapp

If you look inside the build directory you'll see a file called snapp_conf.json. This file has to exist and has to contain a correctly formatted JSON. This object may contain certain properties that will modify the application behaviour if found, if they are missing the application will use default values. The values can be changed at run-time but the changes will not be applied until the application gets restarted. The following are all of the valid properties and their effects:

"port": <number>
Default value: 80
Valid values: 0 <= port < 65536

Defines the port on which Snapp will listen for connections.

"uploadFileSizeLimit": <number>
Default value: 10000000
Valid values: 0 < uploadFileSizeLimit

Defines (in bytes) the maximum size allowed for uploaded projects. If a user tries to upload a larger one they will get notified about the maximum size allowed (in MB). Note that the default limit is kinda low and should be able to be set quite higher on most machines and networks.

"compressStaticFiles": <boolean>
Default value: true
Valid values: true | false

If set to true, static resources (.js, .css, ...) will be compressed before being sent to the client. This should only be disabled if you plan on setting up a proxy server that will manage compression.

6. Launching Snapp

To start the application you just need to execute node and pass it the application's entry-point file as an argument. Like this:

node build/snapp/Snapp.js

You'll see the following output:

<INFO> [<timestamp>] - Snapp.js::Snapp listening on port <port>.

You can now access the given port through any browser and access the application. Also, a new log directory will be created in the build folder. The application logs will be created inside. They rotate daily.

Even though launching the application like this works and may be enough for your use case if you want the application to be up 24/7, and recover from crashes, you will need to set up a more resilient system.

It is recommended to just use the forever module, as it works across all systems and is very easy to set up.

npm -g install forever
forever start build/snapp/Snapp.js

If you are on Windows you could also look into setting up a Windows service by using nssm.