From code to cloud

ashleysimons.com on DigitalOcean App Platform

Created and hosted by Ashley Simons

Use the arrow keys or Space to navigate.

What is Node.js?

Node.js is a runtime that runs JavaScript on the server.

A database-driven web app powered by Node.js Step one: a browser requests https://ashleysimons.com, the Node.js server handles the request, and the database looks up page content. Step two: the database returns data, Node.js builds HTML and CSS, and the browser displays the page. https://ashleysimons.com JS 1. Request the page Web browser Requests the homepage Node.js server Handles the request Database Looks up page content Request Query 2. Return dynamic content Web browser Displays the page Node.js server Builds HTML + CSS Database Returns the data HTML + CSS Data

The server uses database data to generate dynamic content.

Install Node.js on Windows

  1. Visit nodejs.org. Choose LTS (Long Term Support) and download the Windows Installer (.msi) for your PC.
  2. Run the installer, accept the licence, and keep the default options, including npm and Add to PATH. Click Install, then Finish.
  3. Open a new Command Prompt (search for cmd in Start) and run these commands:

node --version
npm --version
          

Both commands should print a version number. You’re ready!

Install Visual Studio Code

  1. Visit code.visualstudio.com/download and download the Windows User Installer (.exe) for your PC.
  2. Run the installer, accept the licence, and keep the default options. Leave Add to PATH checked, then click Install.
  3. Click Finish to launch VS Code. Open a new Command Prompt and check the installation:

code --version
          

Version details should appear. Your code editor is ready!

Open a folder & set up Codex

  1. In Windows File Explorer, create a folder named web-app-demo in your Documents folder.
  2. In VS Code, choose File > Open Folder and select web-app-demo.
  3. Open Extensions with Ctrl+Shift+X. Search for Codex and install Codex by OpenAI.
  4. Open Codex and choose Sign in with ChatGPT. Complete sign-in in your browser, then return to VS Code.

Trust the project & find Codex

  1. For the folder you created, accept the workspace trust prompt. If it is in Restricted Mode, press Ctrl+Shift+P, run Workspaces: Manage Workspace Trust, and choose Trust.
  2. Click the Codex icon in VS Code. If it is hidden, press Ctrl+Shift+P and run Codex: Open Codex Sidebar.
  3. Start a new chat. The input box at the bottom of the Codex panel is where you describe the changes you want.

Codex input

Describe what you want to build or change…

Create a basic Sails.js app

Open Command Prompt and run these commands one at a time:


npm install -g sails
cd "%USERPROFILE%\Documents\web-app-demo"
sails new hello-world
          

When asked, choose 2. Empty for a basic project.
Wait for dependencies to finish installing, then run:


cd hello-world
code .
          

code . opens the current project folder in VS Code.

Hello world with Codex

With hello-world open, enter this in the Codex input:

Example prompt

Change this Sails app’s homepage to “Hello world from Ashley Simons” and add simple CSS.

  1. Send the prompt, let Codex edit the files, and review the changes.
  2. Choose Terminal > New Terminal. Run cmd to switch to Command Prompt, then run sails lift from the project folder.

View http://localhost:1337 in your browser.
Stop: Ctrl+C in the server terminal. Restart: run sails lift again.

Why use Git?

Git is version control: a history of changes to your code.

  • Save checkpoints. A commit records a snapshot of your project with a message explaining the change.
  • Recover working code. Compare versions and restore earlier changes when something breaks.
  • Work together. Branches let you develop changes separately, then merge them into the project.
  • Track releases. Know which version of your code you are deploying.

Commit before and after a Codex task so you can review what changed.
Git works locally; Bitbucket hosts a shared copy of the repository online.

Install Git on Windows

  1. Visit git-scm.com/install/win and download the Git for Windows installer for your PC.
  2. Run the installer. Keep the default options, including Git access from the command line and third-party software, then finish setup.
  3. Restart VS Code and open a new Command Prompt. Verify Git and set your commit identity:

git --version
git config --global user.name "Your Name"
git config --global user.email "[email protected]"
          

Replace the name and email with your own. They identify the author of your commits.

Use Git in Visual Studio Code

  1. Open the hello-world project folder. Press Ctrl+Shift+G to open Source Control. Choose Initialize Repository if the project is not already using Git.
  2. Check .gitignore before your first commit: exclude node_modules/, .tmp/, and local .env files.
  3. Save your files. Click each file under Changes to review its diff, then click + beside the files you want to stage.
  4. Enter a message such as “Add styled hello world homepage” and click Commit to save the staged changes in Git history.

Repeat: edit, review, stage, commit. A commit is saved locally; Push sends it to a configured remote.

Connect to private Bitbucket

  1. In Bitbucket, choose Create repository in your workspace and project. Name it hello-world and keep Private enabled.
  2. Create an empty repository without a README or .gitignore. Copy its HTTPS clone URL.
  3. With your first local commit saved, open the hello-world terminal in VS Code. Run cmd, then these commands:

git branch -m master
git remote add origin PASTE_HTTPS_URL_HERE
git push -u origin master
          

Replace PASTE_HTTPS_URL_HERE with the copied URL.
Complete the Git Credential Manager sign-in, then confirm your files appear on master in Bitbucket.

Sign up to DigitalOcean

  1. Visit digitalocean.com and choose Sign Up.
  2. Create your account using your email address and complete the email verification and onboarding steps.
  3. Add a valid payment method when prompted to activate your account for cloud resources.
  4. Open the App Platform dashboard. This is where we will create and manage our web app.

App Platform builds and hosts the app from our Bitbucket repository.

Install Docker on Windows

  1. If WSL 2 is not installed, open Command Prompt as administrator, run wsl --install, and restart Windows when prompted.
  2. Download Docker Desktop for Windows for your PC and run the installer. Use the WSL 2 backend.
  3. Launch Docker Desktop, complete setup, and wait until its engine is running in Linux containers mode.
  4. Open a new Command Prompt and verify the installation:

docker --version
docker run --rm hello-world
          

The test container should print “Hello from Docker!”

Prepare Docker with Codex

Example prompt

Look at this Sails.js project and set up a production-ready Dockerfile for DigitalOcean App Platform. Add .dockerignore, use a supported Node.js image, build Sails assets, and run as non-root in production. Listen on 0.0.0.0 using PORT (default 8080). Use environment variables for secrets; document database/session setup and local test commands.

  1. Review the generated files. Ask Codex to build and test the container locally and resolve any errors before deployment.
  2. In Source Control, stage the Dockerfile, .dockerignore, and related app changes. Commit as “Add production Docker setup”.
  3. Push the commit to Bitbucket’s master branch.

Create the App Platform app

  1. In App Platform, choose Create App, then Bitbucket as the source. Connect your account and authorize DigitalOcean to access the repository.
  2. Select your private hello-world repository and branch master. Enable Autodeploy for future pushes.
  3. Confirm the Dockerfile build and Web Service type. Match the HTTP port to the app: 8080 for our setup.
  4. Set NODE_ENV=production and PORT=8080. Add the required database/session configuration and encrypt secret values.
  5. Review the region, resources, and price, then choose Create Resources. Follow deployment logs and open the app’s live URL when ready.