In this post we will see how can we setup an express web application and how to deploy an node.js based express web application.
Step 1: Creating an web application in express.
To create a express application skeleton we need to install express generator from npm:
Check available option while creating an express app:
After installing the express generator, we will create an express sample application:
Now go to the application folder and install dependencies:
On Mac OS or Linux, run the app with this command
On Windows, use this command:
The generated app has the following directory structure:
Then load http://localhost:3000/ in your browser to access the app.
OK, now our express app is created and running on localhost.
Step 2: Let us setup our Web App Server in Azure:
Sign in to your Azure portal.
Go to web app service as below:
Create a web app and define the App service Plan
Choose a pricing tier. (For demo purpose you can choose a Free tier)
After choosing and filling all the options click on create. You web app will take about 2-3 mins in creation.
After it is created, open it and choose deployment options in the menu
choose Local Git Repository to fetch our local web app we just created:
For the first time it will ask you about the credentials setup. please define the git credentials.(Give a username and password)
This will create a git clone url for your application. Go to overview section in the menu and copy the git clone URL.
Now let us come back to our express app.
Make sure you have git installed in the local system.
Go to your web app folder and open git bash console follow the below commands to deploy you app on Azure
- initialize your app folder
- Connect to remote git URL you create above
- Add all the files to Queue
- Start the first commit
- Push the master files
You will see the logs obviously that deployment is successful.
After this go to your Azure app URL like this -> youapp.azurewebsites.net and you will see that your app is up and running.
Hope it helps!
For any queries contact me here.
Check the official docs for more detailed insights: