PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, August 1, 2022

[FIXED] How to upload back-end to the hosting with database?

 August 01, 2022     dreamhost, ftp, hosting, node.js, phpmyadmin     No comments   

Issue

I have never did back-end with upload that's why I am asking.

So I have build my project in a folder "Pro" where I have one folder named "Web" which contains React.js application, and other folder named "Server" which has all info about server and database written with Node.js. I have achieved to run this project locally, but I do not know how to upload it online. About "Web" - I can do that easily, just by running npm run-script build I can upload then build folder to the FTP panel.

First question:

What about server side? How should I upload it? Also, buy running npm run-script build and putting it in the same folder online? It will create two files and folders with the same name?

Second question:

Locally, I was connecting to MySQL like this:

const app = express()
const port = process.env.PORT || 5000

app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())
app.use(cors())

// MySQL
const pool = mysql.createPool({
    connectionLimit: 10,
    user: "root",
    host: 'localhost,
    password: "",
    database: "mydatabase"
})

What should I change inside of it so it will work online? My database name online is "database.myqsl", should I put http:// in front of it? I literally know nothing. I use DreamHost with PHPMyAdmin and MySQL.


Solution

If anyone has the same problem, here is the solution: You don't need additional service for that, DreamHost can handle the Node.js. For calling the API you will need additional domain, it can be a subdomain of your website. After creating a subdomain on the DreamHost, go to Manage Domains -> "Edit" under the Web Hosting Column -> under the Web Options chek both "Passenger" and "Node.js" and save it. You don't need to npm run-script build anything, it won't work anyway. After that upload all your files of the folder where you run your Node.js into the FTP outside of /public folder. And then, just call your api's like this on front-end: Axios.get('https://server.yourdomain.com/login') or whichever API call you use and it works perfectly. Also make sure that both of your front-end and back-end domain are https secure.

Articles for you to help:

https://help.dreamhost.com/hc/en-us/articles/216635318-How-to-enable-Node-js

Also, my app.js' SQL connection looks like this:

const pool = mysql.createPool({
    connectionLimit: 10,
    user: "myuser",
    host: 'mysql.site.us',
    password: "site_us_pass",
    database: "db_us"
})


Answered By - user18150656
Answer Checked By - Senaida (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing