Step by step guide to deploy your Node.js app

  • 1
    Installing the NodeChef CLI

    Make sure Node.js is installed on your computer which should be the case if you are deploying Meteor.js or Node.js.

    Install the CLI by running the below command:

    npm install -g nodechef-cli
  • 2
    Prepare your app for deployment

    Generate a package json file in the root directory of your application files. By default, the nodechef platform executes your code using the latest node js version. To specify a different version, use the "engines.node" attribute in the package.json file. Note you must specify the version explicitly. eg: "node" : "0.10.41". By default, the entry point of your application is the index.js script. To specify another script as the entry point, use either the "main" or "scripts.start" attribute.

    On deployment, your local node_modules folder is not included in the zip package uploaded to the server. Modules from your package.json are cached on the build server for faster builds.

    You can retrieve the Network address to use for the the listening socket from the environment variables process.env.PORT and process.env.BIND_IP. Hardcoded port numbers will not work on the nodechef platform.
    Express.js example:
    app.listen(process.env.PORT, process.env.BIND_IP);

    Working with NPM scripts

    By default to start your application NodeChef searches for a scripts.start in your package.json. In case you want to customize your build, you can also include a postinstall script as well which NodeChef will run after running npm install

    In step 5 we will show you how you to start your app with another script other than the start script. This is useful in cases where the same code base serves different functions such as a background worker and also the web app layer

    "scripts": { "start": "node app.js", "worker": "node jobs.js", "postinstall": "echo 'meow'" <--- Will run after npm install }

    Connecting to your database

    The connection string to the database can be retrieved from the process.env.DATABASE_URI or process.env.DATABASE_URL environment variable. This value is a platform default variable that is automatically set on your behalf. You can however override this value if using an external database.
  • 3
    Deploy your cluster

    Log in and navigate to the Dashboard. Click on deployments and complete the form. You will be required to select the size of your container and the region where your cluster is to be hosted.

  • 4
    Environment variables

    If you will like to launch your app with custom environment variables such as ROOT_URL pointing to your domain, follow the below steps.

    • Create a file in the root directory of your app with name env.json. Env.json is completely arbitrary you could name this file with a name more suitable for your use case such as; env_dev.json or env_prod.json
    • Edit the file using the JSON syntax below and save the file. ROOT_URL is only for demonstration purposes. If you however do not set this variable the default ROOT_URL is http://[appname-][nodechefid]
      { "ROOT_URL" : "", "MY_OTHER_VAR" : "MY_VAR_VALUE" }
      The CLI JSON parser does not accept single quotes. Environment variables can also be configured after deployment from the web dashboard.
  • 5
    Launching your app

    From the command prompt or terminal log in and then deploy your app.

    // Log in once and you will always be logged in on your computer until you log out nc login -em -pw ***** nc deploy -i simple-todos -e env.json


    Required. Specify the name of your app. Note this name must match the name used when creating the cluster from the dashboard. If there is a mismatch, the CLI will prompt you to create a new cluster. You must disagree to this action in such a case to avoid possible charges.

    Optional. Deploy your app with environment variables created in step 3.

    Optional. Use this switch to specify another script in your package.json other than the start script to initiate your app.

    Reference the package.json script segment shown at step 2 under working with NPM scripts. The below command will start your app using "node jobs.js" instead of the start script "node app.js"

    nc deploy -i simple-todos -cmd worker

    Optional. Whenever you deploy your app, a new container is created which replaces the old one. The intent is to allow a seamless upgrade without any of your clients ever hitting an empty page. However for this to be possible, the new container has to completely load and ready to accept incomming connections. This parameter allows you to control how long in seconds the container manager will wait before replacing your old container with the new one. The highest value that can be specified is 60. Note the usage of a double hyphen before startupwait. eg: deploy -i simple-todos --startupwait 10

How to deploy with just the command [nc deploy]

In the above steps, we created an environment variable file and we always have to specify the name of the app to be deployed with the [-i] option. You can however create a file with name ncmanifest.json in the root directory of your project folder. You can then enter the name of your app together with your environment variables as seen below:

{ name: "simple-todos", env: { PAYMENT_API_KEY: "", ROOT_URL: "" }, startupwait : 15 }

Whenever the CLI detects the ncmanifest.json file in the root directory of your application, it will automatically attempt to parse the name of your app and other parameters.

Base container image

The NodeChef base image runs Ubuntu 14.04 and comes with the below listed set of packages pre-installed.

node.js build-essential wget putty-tools curl rsync phantomjs ca-certificates imagemagick graphicsmagick libcairo2-dev poppler-utils libjpeg-dev wkhtmltopdf libssl-dev xfonts-base xfonts-75dpi libpoppler-qt4-dev

Startup script

In some cases you might want to install additional ubuntu packages other than the ones listed above. To do so, Navigate to the Task manager on the dashboard and click on App actions → Startup bash script. Write the bash script intended to run on Ubuntu which will install the package and use the save script button to trigger this update.