Hey i'm trying to run nodemon to perform the command npm start which uses concurrently to open 3 nodejs processes
this is my package.json
{
"name": "web",
"version": "1.0.0",
"description": "Classic website",
"main": "index.js",
"scripts": {
"site": "node site/index.js",
"socket": "node socket/index.js",
"bots": "node bots/index.js",
"start": "concurrent \"npm run site\" \"npm run socket\" \"npm run bots\" "
},
"keywords": [
"gsa",
"web"
],
"author": "sas",
"license": "ISC",
"dependencies": {
"child_process": "^1.0.2",
"concurrently": "^3.5.1",
"express": "^4.16.2",
"express-handlebars": "^3.0.0"
}
}
However when i run nodemon i get an error -
Error: Cannot find module 'D:\skindole\index.js'
What command exactly are you entering when you run nodemon? I think perhaps if you remove "main": "index.js", from the package.json you may have success.
I think what you want to do is in the start scripts for each of the site, socket, and bots replace node with nodemon.
I ran into the same issue with concurrently, however, adding --raw param to concurrently did a trick for me.
"scripts": {
"client-install": "npm install --prefix client",
"start": "node server.js",
"server": "nodemon server.js",
"client": "npm start --prefix client",
"wave": "concurrently --raw \"npm run client\" \"npm run server \""
},
Try using && instead of concurrent?
"start": "npm run site && npm run socket && npm run bots"
Related
I'm new to Nodejs, normally when I make a project, I install the dependencies myself, and in order to run the project set something like this in the packaje.json:
"scripts": {
"dev": "nodemon server.js"
}
and then I just run my project with something like this npm run dev
But in a project made by someone else it doesn't seem to be that simple because it has the dependencies like this:
{
"name": "proyecto API",
"version": "1.0.0",
"description": "proyecto Main Backend Repo",
"main": "index.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "cross-env NODE_ENV=production node --harmony index.js",
"dev": "cross-env NODE_ENV=development nodemon --harmony index.js",
"lint": "eslint --ext .js --ignore-path .gitignore .",
"lint:fix": "eslint --ext .js . --fix",
"superuser": "node --harmony createSuperUser.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/proyecto-Network/lolagato"
},
"author": "gatito",
"license": "MIT",
"bugs": {
"url": "https://github.com/proyecto-Network/lolagato/issues"
},
"homepage": "https://github.com/proyecto-Network/lolagato/erths",
"dependencies": {
"#google-cloud/storage": "^5.14.2",
"cookie-parser": "^1.4.5",
"cors": "^2.8.5",
"express": "^4.17.1",
"jsonwebtoken": "^8.5.1",
"mongo-project": "^1.0.1",
"mongodb": "^4.1.0",
"morgan": "^1.10.0"
},
"devDependencies": {
"cross-env": "^7.0.3",
"nodemon": "^2.0.12"
}
}
Apparently here I can't just do npm run dev because as you can see in the packaje.json it comes out this:
"dev": "cross-env NODE_ENV=development nodemon --harmony index.js"
So my questions are, how can I run this project on my PC and what does that say "cross-env" and --harmony mean?
I have to install all that that appears in the packaje.json?
Just do,
npm install
This will install all the required dependencies. If you notice, in the devDependencies there is cross-env which is required for your npm run dev.
Once the dependencies are brought up, do npm run dev.
Or you could just do -
nodemon index.js
or
nodemon --harmony index.js
To see what happens.
cross-env NODE_ENV=development is just setting the environment variables. From their npm page -
cross-env makes it so you can have a single command without worrying about setting or using the environment variable properly for the platform.
How to run Nextjs app and Express server concurrently using npm concurrently package?
I have a project which is created using Node Express as the backend and NextJs as the frontend. I want to use concurrently npm package to start both Express server and NextJs frontend using npm run dev. The server uses port 5000 and the frontend uses port 3000 And the Folder structure as follows.
1.
|-next-bootstrap-express-app.
|frontend(NextJs App)
|.env
|package.json
|src
|server.js
|package.json
package.json(next-bootstrap-express-app):
{
"name": "next-bootstrap-express-app",
"version": "1.0.0",
"description": "Next Bootstrap Express App",
"main": "server.js",
"scripts": {
"frontend-install": "npm install --prefix frontend",
"start": "nodemon server.js",
"server": "nodemon server.js",
"frontend": "npm start --prefix frontend",
"dev": "concurrently \"npm run server\" \"npm run frontend\""
},
"author": "test",
"license": "ISC",
"dependencies": {
"bcryptjs": "^2.4.3",
"config": "^3.3.6",
"express": "^4.17.1",
"express-validator": "^6.12.1",
"jsonwebtoken": "^8.5.1",
"mongoose": "^6.0.2",
"request": "^2.88.2",
"concurrently": "^6.2.1"
},
"devDependencies": {
"nodemon": "^2.0.12"
}
}
How can I use concurrently npm package to start Nextjs 3000 for client and Express Server which uses port 5000 for admin.
In your next-bootstrap-express-app directory's packages.json file you can include your frontend script like this
"frontend": "cd ./frontend && npm run dev"
Then you can run npm run dev command from the next-bootstrap-express-app directory.
My app runs locally with no issues by its failing on Heroku
package.json
{
"name": "app name",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"start": "nodemon app.js"
},
"engines": {
"node": "14.17.0"
},
"author": "",
"license": "ISC",
"dependencies": {
"body-parser": "^1.19.0",
"express": "^4.17.1",
"mongoose": "^5.12.9"
}
}
Procfile
web:node app.js
its returning the below error
sh: 1: nodemon: not found
Any help on how to make this work?
The nodemon is installed globally on your machine that's why you are able to run it on your machine. When you are pushing it on Heroku it is showing the error because there is nothing like nodemon.
Also, Heroku doesn't need nodemon so just replace your start script:
node app.js
and change your Procfile to this:
web: npm start
Even I had the same issue.
You just have to remove nodemon from start script
It has to be iin this way;
"scripts": { "start": "src/index.js", "dev": "env-cmd -f ./config/dev.env nodemon src/index.js" }
I realize that this is most likely a duplicate question. I'm new to nodemon and I'm trying to establish a server for a Vue JS project with nodemon. I'm trying to run eslint with nodemon and can't figure out why I keep getting the error message. If I remove npm after --exec it will tell me ''run' is not recognized, and if I remove that I will get ''lint' is not recognized and so on.
My package.json file:
{
"name": "server",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "nodemon src/app.js --exec 'npm run lint && node'",
"lint": "eslint **/*.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"eslint": "^4.16.0",
"nodemon": "^1.14.12"
}
}
I have also tried this code in my start scripts:
"scripts" : {
"start": "./node_modules/nodemon/bin/nodemon.js src/app.js --exec 'npm run lint && node'",
"lint": "./nodemodules/.bin/eslint **/*.js"
}
Where is tells me that "." is not recognized as an internal external command.
I've installed nodemon into my server folder and in the project directory as well as globally. I have done the same with eslint as well.
i had the same problem today. did some google stuff and found that this is not working anymore. so i tried this
"scripts": {
"prestart": "npm run lint ",
"start": "nodemon src/app.js ",
"lint": "./node_modules/.bin/eslint src/*.js"
},
when you npm start node will run the pre-start script before the start script.Once a file being updated this pre-start wont run by the nodemon.So for that we have to call the nodemon events.So create a nodemon.json on root folder and paste following.
{
"events": {
"restart": "npm run lint"
}
}
you can read more nodemon config options from here nodemon config .There are more nodemon events.you can read them from here event restart
PS:im very new to this. :)
EDIT1:
You can use as follows. this dont need a nodemon config;
"scripts": {
"start": "node src/app.js",
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "nodemon src/app.js --exec \"npm run lint --fix && node\"",
"lint": "eslint --fix **/*.js "
}
for run use npm run dev it will run es lint + nodemon. this is for windows cmd command.if you are using bash terminal, remove \ in "dev" ;
"dev": "nodemon src/app.js --exec "npm run lint --fix && node""
I had the same problem.
For some reason you can't use simple quotes in npm scripts.
Use escaped double quotes instead. This should work:
"start": "nodemon src/app.js --exec \"npm run lint && node\""
install it globally for making it available on path.
npm i -g nodemon
or if using yarn
yarn global add nodemon
and if you tried this approach and it didn't work.
you should try running it locally..
you have to create a script in your package.json like this
"script": {
"server" : "nodemon scriptFile.js" //name of the file you want to run
}
then use,
npm run server
but before it,
install nodemon locally.
check it, if it is available on package.json
I'm starting a project in Vue.JS and I'm a little new to nodemon.
Here is my package.json file
{
"name": "server",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "nodemon src/app.js --exec 'npm run eslint'",
"lint": "eslint **/*.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"eslint": "^4.16.0",
"nodemon": "^1.14.12"
}
}
I can get nodemon to run through app.js with "nodemon src/app.js". I've tried a whole bunch of combinations after --exec and haven't had any luck.
The correct way is (in package.json and windows):
"scripts": {
"start": "node index",
"start-dev": "nodemon --exec \"npm run lint && node index\"",
},
This works pretty fine for your use-case.
nodemon src/app.js --exec "npm run lint && node"
or you can write nodemon.json file in your root directory
{
"watch": ["src"],
"ignore": ["**/*.test.js", "**/*.spec.js", ".git", "node_modules"],
"exec": "npm run lint && node src/app.js"
}
Im using nodemon version 1.19.4. You just missed the "events" key. The right way would be to create a nodemon.json in your root folder like that, then a lint script in your package.json with your lint command:
{
"watch": [ "src" ],
"ignore": ["**/*.test.js", "**/*.spec.js", ".git", "node_modules"],
"events": {
"restart": "npm run lint"
}
}
Here you can check about Nodemon Events.
When using events you don't need to manually handle your application state (restart, crash, node execution, etc), just put what you want to happen when nodemon refreshes.
I've been using a custom script for a while now which I finally published to npm.
Check it out here: https://github.com/theoephraim/lint-fix-nodemon
This helps avoid double restarts when eslint fixes your files as well as not failing on the initial run if eslint has fatal errors.
Hope it helps!