Deploy your first Node.js CRUD Application on cPanel with Newsys Managed Service

Aditya Padhi
5 min readAug 8, 2020

--

In this tutorial, we will build a super simple Node.js Express application for CRUD (Create, Read, Update, Delete) operations and we will use MySQL managed database service along with the Node.js hosting service on cPanel with Newsys Web Hosting for hosting our application.

Overview of the CRUD API

First, we will start with an Express web server and we will add the database configuration for MySQL database and create a Testimonial model and a controller to control the module. Then we will define routes for the CRUD operations.

Crafting the Node.js Application

Login / Create an account with Newsys. For small scale apps, I personally prefer the Basic plan which starts as low as 59/- per month with a .xyz domain for development purposes. But for enterprise usage, I recommend the purchase of the Professional / Unlimited plans.

  • After logging in navigate to Services. ( Client Area > Services )
  • Click on the product that you have purchased and on the left sidebar ‘Login to cPanel’.

NB: You will also receive a mail regarding the cPanel username and credentials when you order any product.

After logging in to cPanel search for Node.js Application.

Source: Newsys Hosting Solution
Click on Create Application.

— Choose the Node.js version of your choice from the available list and other details as shown in the figure below.

NB: Your Application root will be the folder from which your application will operate.

Click on Create Button on the Top Right to craft your application.

Boom your application is ready.

You should be able to check your node application at https://<domain-name>. Copy the command highlighted to get started with building the application.

Configure and note your database credentials

Before getting started with the application let us create the database and provide appropriate privileges to the database user.

Search for MySQL in the cPanel search bar. Click on MySQL databases.
Create a new database with a database name.

Scroll down to create a new MySQL User.

NB: Do note the database name, username, password in the process.

Click on create a user.

After creating, Go back and scroll down again to provide user the appropriate privileges.

Click on Add.
Select the appropriate privileges and click on Make Changes.

The username for me as mentioned in the figure above is cetbin_testuser and the database is cetbin_apibricks.

Creating the table for our testimonials:

  1. Open phpMyAdmin tool in the cPanel to access the database created via the frontend tool.
Clicking on this will redirect you to the application.

Click on the database and then click on SQL to find ‘Run query/queries on database <databasename>’:

Run the query on the field provided and click on Go.

Installing the dependencies

NB: Skip this, If you already have your application ready you can directly upload your files with the node_modules folder to the APPLICATION ROOT folder using FileManager.

Search for the Terminal on cPanel and enter the same.

Enter the copied code, paste and hit enter.
npm init -y
npm install express body-parser cors mysql --save

Adding your code to the Application using File Manager.

Search for File Manager and click on the same to navigate.

Folder Structure under ( /home/<username> )

Your directory structure will be the same as shown in the figure on the left.
Create the folders if not present already using the options provided on the Top menu.

Make sure that you are working on the same folder which you mentioned as your application root.

The final output.
  1. Now create the index.js file and populate the code as below.

2. Create the db.config.js file and populate the same as below and save the changes.

Fill the user, password, and database name as noted earlier in the tutorial.

3. Define the testimonial routes in the routes folder. (testimonial.routes.js)

4. Define the model in the ‘models’ folder. (testimonial.mode.js)

5. Define the controller in the ‘controllers’ folder. (testimonial.controller.js)

Restart the Node.js server

Test the REST API Service

Testing the GET service https://<domain-name>/api/testimonials.
Testing the POST service https://<domain-name>/api/testimonials.
Testing the update PUT service https://<domain-name>/api/testimonials/:id.
Testing the update GET service https://<domain-name>/api/testimonials/:id.
Testing the DELETE service https://<domain-name>/api/testimonials/:id.

Hurrah! We just built our first Nodejs application on cPanel with partially managed servers.

Thank you for showing your interest. If you liked it please do like.

Keep learning!

Regards,
Aditya Padhi

--

--