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.
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"
})