node --version
npm --version
. If
installed correctly these steps will both give you a number as the terminal
output.
If node
and npm
are installed, create a new directory with
mkdir [app_name]
- replacing [app_name]
with the name of your application.
Next navigate into the directory with cd [app_name]
and run the following
commands:
npm init
npm install express
app.js
at the root of the
folder and use the following to set up an endpoint for your application:
app.js
file, you can run the Express application with the
following command:
node app.js
You should now see your app running at
https://localhost:3000.
node --version
npm --version
mkdir [app_name]
cd [app_name]
app.js
file with the content above
node app.js
FROM vm/ubuntu:18.04
FROM
instruction tells webapp.io what base
to use to run tests from. There can only be one FROM
line, and in this case
we’re using the ubuntu:18.04
virtual machine image.
If you’re familiar with AWS Ec2 Instances, this is similar to creating a virtual
machine from the ubuntu 18.04 image.
RUN curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
RUN sudo apt-get install -y nodejs
RUN sudo npm install npm@latest -g
RUN
instruction will run the given script,
and fails the Layerfile if the script fails. In this case, we’re using the RUN
command to install the dependencies we need to build and run the Express
application.
In this case we’re using the RUN
instruction to download Node JS and npm.
COPY . .
COPY
instruction moves files from your
repository to the virtual machine. The Layerfile will pick up on the files in
the repository that you are making the commit for, and will copy those files
into the virtual machine so you can run you project.
RUN npm install
RUN
commands above, this will execute the given script
npm install
, which will install the dependencies for the Express app.
RUN BACKGROUND node app.js
RUN BACKGROUND
instruction is the RUN
instruction with the BACKGROUND
flag. This tells webapp.io to continue to the
next step in the Layerfile instead of waiting for the given script to run. The
reason why we do this is that node app.js
will essentially block the terminal
while the Express app is running. We want to continue to the next step so that’s
why we use RUN BACKGROUND
here.
EXPOSE WEBSITE http://localhost:3000
EXPOSE WEBSITE
instruction
instruction creates a link to view the virtual machine at a specific port. We
use EXPOSE WEBSITE
to expose the virtual machine on port 3000 which is where
the Express application runs after running node app.s
. We use EXPOSE WEBSITE
here so we can get a link to our Express JS app to share with stakeholders
involved in our projects.
Layerfile
(no file extension) in the root of your Express
JS application. If you haven’t already, install webapp.io onto your repository
containing your Express JS app. Once done, simply create a commit and push your
Express app to the repository with the new Layerfile. Webapp.io will pick up on
the Layerfile and build your Express JS application according to the steps in
your Layerfile.