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
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?
So I was having this issue of node not restarting the server when there changes made on the server.js file. I fixed it by editing the package.json file. However, once fixed, the npm start command starts the server.js file: [nodemon] starting `node server.js
How do I start my react app then? npm start was the command I used before
Most probably your set your package.json file to
"scripts": {
"start": "nodemon server.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
Change your server package.json to something like this:
"scripts": {
"server": "nodemon server.js",
"test": "echo \"Error: no test specified\" && exit 1"
then run the command
npm run server --this will start your server.js
Nodemon has nothing to do with the client-side(React app). So, before running npm-start:
Make sure you are in the correct directory cd [directory-name]
It's better to separate your front-end and back-end in a separate folder
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/
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'm trying to deploy my Express server to my Heroku app, but every time I do, I get an error and it crashes.
I setup my Procfile with the following code: web: node /src/server.js
Where server.js is not in the root of the directory. However, when I try to start the server, I get an error in the logs: Error: Cannot find module '/src/server.js'
When I run the app locally, I have to run npm start in order for it to run the server correctly. Here is the relevant "scripts" portion of my package.json file:
"scripts": {
"start": "NODE_ENV=dev nodemon ./src/server.js --exec babel-node",
"prebuild": "rimraf dist",
"build": "babel ./src -d dist --presets es2015,stage-2 --ignore spec.js,node_modules",
"serve": "NODE_ENV=production node dist/server.js",
"start_babel": "babel-node ./server.js --preset=babel-preset-es2015",
"test": "echo \"Error: no test specified\" && exit 1",
"lint": "eslint ."
}
Since the Procfile overrides the package.json script commands, why is it having trouble finding my file when I've explicitly set it?
I'm not sure about the leading slash. Does using ./src/server.js help at all?