By jtt7
I am just starting with nodejs and have a small app to test on an Ubuntu server. What is the “standard tool” to deploy the app and install the dependency modules? looking for the simplest one, just copy the files and install the modules. Thanks for any insight!
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
I use Capistrano for NodeJS deployments.
For starters, here’s how one Cap job looks:
(my example uses Chef to find nodes to deploy to)
require "capistrano/chef"
require "chef/node"
set :user, "DEPLOY_USER_GOES_HERE"
set :chef_environment, ENV['CHEF_ENVIRONMENT'] if ENV['CHEF_ENVIRONMENT']
if fetch(:chef_environment).nil?
abort "CHEF_ENVIRONMENT environment variable not set. Please set it and try again."
end
set :service_name, ENV['SERVICE_NAME'] if ENV['SERVICE_NAME']
if fetch(:service_name).nil?
abort "SERVICE_NAME environment variable not set. Please set it and try again."
end
service = fetch(:service_name)
chef_env = fetch(:chef_environment)
stripe_key = fetch(:stripe_keyname)
stripe_account = fetch(:stripe_account)
chef_role :node_service, "roles:node-#{service} AND chef_environment:#{chef_env}", primary: true, attribute: "ipaddress"
set :application, service
set :repo_url, "https://GITHUB_KEY_GOES_HER:@github.com/USER_OR_ORG_GOES_HERE/#{service}.git"
set :gitBranch, ENV['BRANCH'] if ENV['BRANCH']
gitHubBranch = fetch(:gitBranch)
set :branch, gitHubBranch unless gitHubBranch.nil?
if gitHubBranch.nil?
abort "BRANCH environment variable not set. Please set it and try again."
end
set :deploy_to, "/install_path/cap_#{service}/"
set :scm, :git
set :keep_releases, 5
set :linked_files, %w{.env}
set :default_env, {
NODE_ENV: 'production'
}
namespace :deploy do
desc 'Install the packages before running the build'
task :install_npm_packages do
on roles(:node_service) do
execute "cd #{release_path} && npm install"
end
end
desc 'Run the build before deploying'
task :predeploy_build do
on roles(:node_service) do
execute "cd #{release_path} && npm run build:prod || npm run build"
end
end
desc 'run tests'
task :run_tests do
on roles(:node_service) do
execute "cd #{release_path} && npm run test"
end
end
desc 'run lint'
task :eslint_code do
on roles(:node_service) do
execute 'name' do
command "cd #{release_path} && eslint **/src/**/*.js"
end
end
end
desc 'Prune packages for production'
task :prune_production do
on roles(:node_service) do
execute "cd #{release_path} && npm prune --production"
end
end
desc 'Restart service'
task :restart_service do
on roles(:node_service) do
execute "sudo service #{service} restart"
end
end
end
after "deploy:run_tests", "deploy:prune_production"
after "deploy:install_npm_packages", "deploy:predeploy_build"
after "deploy:predeploy_build", "deploy:run_tests"
before "deploy:symlink:release", "deploy:install_npm_packages"
after "deploy", "deploy:restart_service"
If you need help, let me know.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.