NodeChef provides a CLI which can be used to update your Cloud Code files using a single command.
The directory structure for your code files does not change, all cloud code files should be under the Cloud directory.
The contents of the public
folder are rather sent to the load balancer instead (You can overide this behaviour). Static assets can be served directly from the load balancer for the best performance.
You can even configure routes on the load balancer
such that /privacy points to privacy.html and so on. You no longer have to hard code routing for static assets.
-cloud/
-node_modules/
twilio
mailgun
jobs.js
main.js Cloud Code functions, require ./app.js here
app.js Express app configuration and request handling logic
-views/ View template files that Express needs to render
hello.ejs
-public/
example.html Static HTML files
favicon.ico Your favicon logo
-stylesheets/ CSS stylesheets
style.css
Remarks
Parse.Cloud.job can only be invoked from the jobs.js module. Invoking this function from the main or any other module will throw an undefined exception.
The minimum requirement to use cloud code is the main.js module. app.js and other example .js modules used in this documnetation are only for demonstration purposes.
The minimum requirement to run jobs is the jobs.js module.
If your app container is in the exited(1) state after deploying cloud code, check your app logs for details on the crash. Exited(1) means your app is not running and requires your attention to fix the defect.
Require Statements
Consider the above folder structure, if you want to require the module app.js from main.js,
use require('./app.js').
Upload your cloud code from the dashboard
If you prefer to use the dashboard without touching the CLI, you can upload your cloud code from the dashboard by following the below steps:
Step 1. On the dashboard, click on App actions → Cloud Code Hosting
Step 2. Click on Upload cloud code on the top right corner of the cloud code hosting section
Step 3. Zip your cloud folder or the contents in your Cloud folder and select it to be uploaded.
Deploying Cloud Code using the CLI
From the command prompt or terminal, CD into the directory which contains the cloud folder and run the below command:
// Log in once and you will always be logged in on your computer until you log outnc login -em info@nodechef.com -pw *****// Deploy cloud code using the below command:nc deploy --ccode -i yourpics
The CLI mirrors the exact folder structure you have on your local development machine. You can view your cloud code directly from your file system.
ARGUMENTS
--ccode
This flag is required when deploying cloud code. This flag will prevent the CLI from deploying the cloud code as a standalone node app.
-i
Specify the name of the app to deploy the cloud code to.
--rebuild
Cloud code is deployed incrementally by using the file __nodechef_cloudcode_track__.json which is automatically created in your cloud folder. When this file is deleted for some reason,
the incremental build is unable to delete resources you have deleted in your local folder. To force the server to delete files that no longer exist on your local file system, you can use this flag with the deploy command.
If a package.json file is present in your cloud folder, the CLI copies it to the remote server without generating a package.json file.