Step 0. Creating the initial source code (optional)
We will create the example source code by using some popular frameworks.
This is optional and you may use an existing project instead or a starter project from
For Node.JS we will use the Express framework for our example.
- Install Express:
npm install express --save
- Generate an example project:
$ npx express-generator
warning: the default view engine will not be jade in future releases
warning: use `--view=jade' or `--help' for additional options
create : public/
create : public/images/
create : public/stylesheets/
create : public/stylesheets/style.css
create : routes/
create : routes/index.js
create : routes/users.js
create : views/
create : views/error.jade
create : views/index.jade
create : views/layout.jade
create : app.js
create : package.json
create : bin/
create : bin/www
$ npm install
run the app:
$ DEBUG=express:* npm start
Your source code has now been generated and created in the directory.
Step 1. Connect to your cluster and create a new namespace or project
Before starting you should make sure that odo is connected to your cluster and that you have created a new namespace (or project if you are using OpenShift).
Creating a new namespace
If you are using Kubernetes, you can create a new namespace with the
odo create namespace command.
$ odo create namespace odo-dev
✓ Namespace "odo-dev" is ready for use
✓ New namespace created and now using namespace: odo-dev
Login to OpenShift Cluster
The easiest way to connect
odo to an OpenShift cluster is use copy "Copy login command" function in OpenShift Web Console.
- Login to OpenShift Web Console.
- At the top right corner click on your username and then on "Copy login command".
- You will be prompted to enter your login credentials again.
- After login, open "Display Token" link.
- Copy whole
oc login --token ...command and paste it into the terminal, before executing the command replace
Create a new project
If you are using OpenShift, you can create a new namespace with the
odo create project command.
$ odo create project odo-dev
✓ Project "odo-dev" is ready for use
✓ New project created and now using namespace: odo-dev
Step 2. Initializing your application (
Now we'll initialize your application by creating a
devfile.yaml to be deployed.
odo handles this automatically with the
odo init command by autodetecting your source code and downloading the appropriate Devfile.
Note: If you skipped Step 0, select a "starter project" when running
odo init and select Node.JS:
$ odo init __ / \__ Initializing new component \__/ \ Files: Source code detected, a Devfile will be determined based upon source code autodetection
/ \__/ odo version: v3.0.0~beta3 \__/
devfile.yaml has now been added to your directory and now you're ready to start development.
Step 3. Developing your application continuously (
Now that we've generated our code as well as our Devfile, let's start on development.
odo uses inner loop development and allows you to code,
build, run and test the application in a continuous workflow.
Once you run
odo dev, you can freely edit code in your favourite IDE and watch as
odo rebuilds and redeploys it.
odo dev to start development on your Node.JS application:
$ odo dev __ / \__ Developing using the my-nodejs-app Devfile \__/ \ Namespace: default
↪ Deploying to the cluster in developer mode ✓ Waiting for Kubernetes resources [3s] ✓ Syncing files into the container [330ms] ✓ Building your application in container on cluster [4s] ✓ Executing the application [1s] Your application is now running on the cluster - Forwarding from 127.0.0.1:40001 -> 3000 Watching for changes in the current directory /Users/user/nodejs Press Ctrl+c to exit `odo dev` and delete resources from the cluster
/ \__/ odo version: v3.0.0~beta3 \__/
You can now access the application at 127.0.0.1:40001 in your local browser and start your development loop.
odo will watch for changes and push the code for real-time updates.