I have a normal React App which runs on Node Server
-node_modules
-src
-Actions
-Components
-Stores
-Server
-server.js
-package.json
Basically when i run npm start React App will run and for suppose i will be able to see the example in localhost:8080
Now my server.js file includes MySql code
var mysql = require('mysql');
var con = mysql.createConnection({
host: "localhost",
user: "yourusername",
password: "yourpassword"
});
con.connect(function(err) {
if (err) throw err;
console.log("Connected!");
});
I have to explicitly run node server.js command to get the connection to mysql and run the queries their.
How do i integrate server.js command in my React App, so that when i run npm start, my MySql connection and the file should execute
npm start, you might be usingwebpack-dev-serverthen, am I right?startscript in package.json to"start": "NODE_PATH=$NODE_PATH:./src node server",. That will call your node server and it will work then.node serverin your npm scripts using&&operator like this"scripts": { "start": "webpack-dev-server --config './webpack/webpack.config.js' && node server" }