I have client and server in a separate folder. I think there is an error in client Script. can anyone help me out with the solution. I want to run both client and server simultaneously. Thanks
my folder structure
----client
----server
package.json inside server folder
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"server": "nodemon server.js",
**"client": "npm start --prefix client",**
"dev": "concurrently \"npm run server\" \"npm run client\""
}
As you have separate package.json files for the server and client, please try this solution
package.json inside the server folder
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"server": "nodemon server.js",
**"client": "npm start --prefix client",**
"dev": "concurrently \"npm run server\" \"cd ./../client && npm run client\""
}
Also you can try this one
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"server": "nodemon server.js",
**"client": "npm start --prefix client",**
"dev": "npm run server & (cd ./../client && npm run client)"
}
Related
I'm deploying Nodejs application to Droplet of Digitalocean.When I start it normal(npm start), it work perfectly.But when i start with pm2 , i get this error in pm2 logs.
Error during Data Source initialization error: password authentication failed for user "root"
this is script in my package.json
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"watch": "tsc -w",
"server": "nodemon dist/index.js",
"typeorm": "node --require ts-node/register ./node_modules/typeorm/cli.js -d ./dist/data-source.js",
"build": "rm -rf dist && tsc",
"start": "NODE_ENV=production node dist/index.js"
},
I dont use root as owner rule when create database on Droplet, but i dont know why it happen, how can i fix it?
Hi all I have stacked with this issue which I don't know the problem I follow to seem instruction for running nodemon and mocha here is the image attach to see more, I run
"scripts": {
"test": "nodemon --exec 'mocha -R min'"
},
try this
"scripts": {
"test": "mocha ***/*.test.js",
"test-watch": "nodemon --exec \"npm test\""
}
from here https://www.prashant-kumar.in/unit-testing-using-mocha-in-node-js/
package.json
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "cd profile-app-server && nodemon server.js",
"client": "cd client/profile-front-end && npm start",
"start": "concurrently \"npm run dev\" \"npm run client\" "
},
npm ERR! enoent ENOENT: no such file or directory, open '/Users/SebastianRusso/Desktop/profile-app/package.json'
when i run them separately, they both work fine. the server is running on 3001, so not to interfere with react.
the app is called, 'profile-app' which holds a 'client folder' which holds, 'profile-front-end'
the app, 'profile-app' also holds 'profile-app-server'
i'm wondering if i have the paths mixed up somehow. I've played around and tried different things, but kind of at a road block now
so basically to make both run, only the client can be in another folder.
i put the server in a separate folder as well, but that was incorrect, and that's why npm start could not find the folder.
in the end i removed the server folder, and changed the code to this and it works (runs both client side and server side)
"dev": "nodemon server.js",
"client": "cd client/avybe-challenge-profile && npm start",
"start": "concurrently \"npm run dev\" \"npm run client\" "
My guess is you need to figure out the path to get from your server package.json to your client package.json file. The client path for your script may need to be slightly altered.
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "cd profile-app-server && nodemon server.js",
"client": "cd ../client/profile-front-end && npm start",
"start": "concurrently \"npm run dev\" \"npm run client\" "
},
Not sure if that's the correct path, but it is probably somewhere along those lines.
This is the portion from package.json :
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node index.js",
"dev": "nodemon --watch app index.js"
},
All my code except the index.js, package.json and node_modules resides in a sub folder called app.
When I run using npm run dev , nodemon watches the changes in app folder and restarts if there's any changes. But won't restart if I make any changes in index.js (entry point)
My folder structure:
|-- app/
|-- node_modules/
|index.js <--- nodemon not watching this file
|package.json
|package-lock.json
Why is it so?
EDIT:
Here's the solution (from #Pedro Filipe):
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node index.js",
"dev": "nodemon index.js"
},
If you're importing files into index.js, I think you just need to do nodemon index.js in order to have the files that interest you watched. I suspect that when you pass the flag --watch [folder_name] it basically just ignores the filename you pass afterwards.
Nodemon detects changes into the files and restarts it automatically.
Currently, you are saying node to run the index.js file which requires restart whenever you want to reflect your changes.
All you need to do is change the "start" command.
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node index.js",
"dev": "nodemon index.js"
}
(Previously commented this answer)
Nodemon watches the entry-point to your project.
Which, In almost all the cases of node project is a single file which eventually imports other files and so on and so forth.
(Assuming that your entry-point is index.js i.e. you're importing your other files in there.) You can simply use the nodemon index.js as the script for your dev
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node index.js",
"dev": "nodemon index.js"
},
Nodemon detects changes into the files and restarts it automatically.
Currently, you are saying node to run the index.js file which requires restart whenever you want to reflect your changes.
All you need to do is change the "start" command.
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node index.js",
"dev": "nodemon index.js"
},
I need to deploy my app on digital ocean, after installing all dependencies i ran my script yarn dev
"scripts": {
"dev": "nodemon --delay 10ms --exec babel-node -- app.js",
"start": "NODE_ENV=stag nodemon --delay 10 --exec babel-node -- app.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
but i want to use pm2, how can i write the command to run this yarn command with pm2.
i will require to run it with whole script to use babel-node and other params