Node.js
Deploy a Node.js application that connects to PostgreSQL using DB migrations.
Assumed Structure
- Entry point:
node/index.js, started vianpm run start - Migrations: managed under
node/migrations, run vianpm run migrate DATABASE_URLis assembled inside scripts from the individual environment variables
Deploy Commands
| Field | Value (example) |
|---|---|
| Setup Command | npm install |
| Pre-deploy Command | npm run migrate |
| Start Command | npm run start |
All commands run from the repository root.
package.json Scripts
Define the following scripts in package.json:
{
"scripts": {
"start": "node node/index.js",
"migrate": "node node/migrations/migrate.js",
"migrate:down": "node node/migrations/migrate-down.js"
}
}
Environment Variables
The PORT environment variable is set by default. Your app should use this value as the listen port.
When a database is selected during app creation, the following variables are also automatically set:
DB_HOST,DB_PORT,DB_NAME,DB_USER,DB_PASSWORDDATABASE_URL— full connection string
Use these to build the connection in your migration scripts and application code.
Starter App
See the starter app for reference: kamui-project/node-starter