Nodemon doesn't start the server - node.js

I installed nodemon to devDependencies and set the script "start" : "nodemon server.js". However, when I do npm start, it throws me this error:
Error: Cannot find module 'C:\Users\win10\Desktop\nodemon\bin\nodemon.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
at Function.Module._load (internal/modules/cjs/loader.js:725:27)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
at internal/main/run_main_module.js:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! question-answer-rest-api#1.0.0 start: `nodemon server.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the question-answer-rest-api#1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
My package.json
{
"name": "question-answer-rest-api",
"version": "1.0.0",
"description": "Back end project for practice",
"main": "server.js",
"scripts": {
"start": "nodemon server.js"
},
"keywords": [
"Express",
"Nodejs",
"Mongoose",
"Api"
],
"author": "Cihan Özcan",
"license": "MIT",
"dependencies": {
"express": "^4.17.1"
},
"devDependencies": {
"nodemon": "^2.0.7"
}
}
I also filled in server.js and tried that way but it didn't work.
My server.js file
const express = require('express');
const app = express();
const PORT = 5000
app.listen(PORT, () => {
console.log(`Server started on port ${PORT}`)
})
There are no any file in the folder. I couldn't find similar error in SO. I installed nodemon as global and checked the global environment in pc. There is no problem with it.
What is the problem ?

Try
npm uninstall nodemon
Then
npm install -g nodemon
It should works

Related

npm install throwing expected "0.15.7" but got "" on new vite project

I just created a new vite project and i am getting the following error when executing npm install.
node.js: 16.17.0
npm: 8.15.0
npm ERR! C:\xxx\GIT\NewTestProject\node_modules\esbuild\install.js:93
npm ERR! throw new Error(`Expected ${JSON.stringify("0.15.7")} but got ${JSON.stringify(stdout)}`);
npm ERR! C:\xxx\GIT\NewTestProject\node_modules\esbuild\install.js:93
npm ERR!
npm ERR! Error: Expected "0.15.7" but got ""
npm ERR! at validateBinaryVersion (C:\xxx\GIT\NewTestProject\node_modules\esbuild\install.js:93:11)
npm ERR! at C:\xxx\GIT\NewTestProject\node_modules\esbuild\install.js:240:5
package.json
{
"name": "newtestproject",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
},
"dependencies": {
"vue": "^3.2.37"
},
"devDependencies": {
"#vitejs/plugin-vue": "^3.1.0",
"vite": "^3.1.0"
}
}
Running cmd as admin solved the issue.

cannot import module when npm start while uploading to server(cpanel) where as it works fine when doing in localhost

While i am working on the localhost everything works fine, nodejs and everything. but when i try to deploy it to the server (cpanel) after making a nodejs application. And when I do npm start (node server.js) it does not work and i get this error.
stdout:
> thewebapp#1.0.0 start /home/proudpos/backend
> node server
stderr:
/home/proudpos/backend/server.js:1
import express from "express";
^^^^^^^
SyntaxError: Unexpected identifier
at Module._compile (internal/modules/cjs/loader.js:723:23)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! thewebapp#1.0.0 start: `node server`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the thewebapp#1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/proudpos/.npm/_logs/2021-08-30T02_57_23_668Z-debug.log
here is my package.json file,
{
"name": "thewebapp",
"version": "1.0.0",
"description": "",
"main": "server.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server",
},
"author": "",
"license": "ISC",
"dependencies": {
"axios": "^0.21.1",
"bcryptjs": "^2.4.3",
"cloudinary": "^1.26.3",
"colors": "^1.4.0",
"dotenv": "^10.0.0",
"express": "^4.17.1",
"express-async-handler": "^1.1.4",
"http-proxy-middleware": "^2.0.1",
"jsonwebtoken": "^8.5.1",
"morgan": "^1.10.0",
"multer": "^1.4.2",
"mysql": "^2.18.1",
"react-router": "^5.2.0",
"redux-devtools-extension": "^2.13.9"
},
"devDependencies": {
"concurrently": "^6.2.0",
"nodemon": "^2.0.12"
}
}
here is my node app in cpanel,
Try using this
const express = require('express');

Unable to find module cors in heroku

I am running a React/NodeJS project on Heroku. My first time installing a project on Heroku. The deployment ran fine, but then I get the following error:
> ProductInventoryApp#1.0.0 start /app
2020-01-12T04:55:41.635051+00:00 app[web.1]: > node ./backend/app.js
2020-01-12T04:55:41.635053+00:00 app[web.1]:
2020-01-12T04:55:42.404864+00:00 app[web.1]: internal/modules/cjs/loader.js:800
2020-01-12T04:55:42.404909+00:00 app[web.1]: throw err;
2020-01-12T04:55:42.404911+00:00 app[web.1]: ^
2020-01-12T04:55:42.404913+00:00 app[web.1]:
2020-01-12T04:55:42.404916+00:00 app[web.1]: Error: Cannot find module 'CORS'
2020-01-12T04:55:42.404918+00:00 app[web.1]: Require stack:
2020-01-12T04:55:42.404921+00:00 app[web.1]: - /app/backend/app.js
2020-01-12T04:55:42.404923+00:00 app[web.1]: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:797:15)
2020-01-12T04:55:42.404925+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:690:27)
2020-01-12T04:55:42.404927+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:852:19)
2020-01-12T04:55:42.404929+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:74:18)
2020-01-12T04:55:42.404931+00:00 app[web.1]: at Object.<anonymous> (/app/backend/app.js:5:12)
2020-01-12T04:55:42.404933+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:959:30)
2020-01-12T04:55:42.404935+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
2020-01-12T04:55:42.404937+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:815:32)
2020-01-12T04:55:42.404939+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:727:14)
2020-01-12T04:55:42.404941+00:00 app[web.1]: at Function.Module.runMain (internal/modules/cjs/loader.js:1047:10)
2020-01-12T04:55:42.404943+00:00 app[web.1]: at internal/main/run_main_module.js:17:11 {
2020-01-12T04:55:42.404945+00:00 app[web.1]: code: 'MODULE_NOT_FOUND',
2020-01-12T04:55:42.404946+00:00 app[web.1]: requireStack: [ '/app/backend/app.js' ]
2020-01-12T04:55:42.404948+00:00 app[web.1]: }
2020-01-12T04:55:42.427634+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2020-01-12T04:55:42.428331+00:00 app[web.1]: npm ERR! errno 1
2020-01-12T04:55:42.430180+00:00 app[web.1]: npm ERR! ProductInventoryApp#1.0.0 start: `node ./backend/app.js`
2020-01-12T04:55:42.430622+00:00 app[web.1]: npm ERR! Exit status 1
The cors has been included in my dependencies. So not sure where the problem lies.
package.json for nodeJS
{
"name": "ProductInventoryApp",
"version": "1.0.0",
"description": "",
"engines": {
"node": "12.13.1"
},
"main": "./backend/app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node ./backend/app.js",
"client-install": "npm install --prefix client",
"server": "nodemon ./backend/app.js",
"client": "npm start --prefix client",
"dev": "concurrently \"npm run server\" \"npm run client\""
},
"author": "",
"license": "ISC",
"dependencies": {
"body-parser": "^1.19.0",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"express-validator": "^6.3.0",
"mongodb": "^3.4.0",
"mongoose": "^5.8.0",
"uuid": "^3.3.3"
},
"devDependencies": {
"concurrently": "^4.0.1",
"cors": "^2.8.5"
}
}
You need move cors package from devDependencies into dependencies. This is because heroku runs your node app in production mode, devDependencies are not installed in production mode.

NodeJS website uploaded to Heroku won't load, can't find dependencies for some reason

Tried to upload my website to an Heroku server.
It's not my first time and I usefully do not encounter any problems. I have added a profcile.
This is the package.json:
{
"name": "exodia-coming-soon",
"version": "1.0.0",
"description": "Coming Soon\r http://exodia.io",
"main": "server.js",
"dependencies": {
"express": "^4.16.3",
"nodemon": "^1.18.4",
"path": "^0.12.7"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "nodemon server.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/Amirh24/exodia-landing.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/Amirh24/exodia-landing/issues"
},
"homepage": "https://github.com/Amirh24/exodia-landing#readme"
}
What matters is the dependencies and
devDependencies part.
When I upload it to heroku and it wont load, the logs show:
2018-09-26T12:09:21.012703+00:00 app[web.1]: > exodia-coming-soon#1.0.0 start /app
2018-09-26T12:09:21.012705+00:00 app[web.1]: > nodemon server.js
2018-09-26T12:09:21.012706+00:00 app[web.1]:
2018-09-26T12:09:21.107321+00:00 app[web.1]: module.js:550
2018-09-26T12:09:21.107325+00:00 app[web.1]: throw err;
2018-09-26T12:09:21.107326+00:00 app[web.1]: ^
2018-09-26T12:09:21.107329+00:00 app[web.1]: Error: Cannot find module '../lib/cli'
When I try to start without nodemon, just node server.js I get:
2018-09-26T11:49:07.146721+00:00 app[web.1]: > node server.js
2018-09-26T11:49:07.146723+00:00 app[web.1]:
2018-09-26T11:49:07.257964+00:00 app[web.1]: module.js:550
2018-09-26T11:49:07.257968+00:00 app[web.1]: throw err;
2018-09-26T11:49:07.257969+00:00 app[web.1]: ^
2018-09-26T11:49:07.257971+00:00 app[web.1]:
2018-09-26T11:49:07.257973+00:00 app[web.1]: Error: Cannot find module './lib/express'
I have installed my 3 dependencies: express, path and nodemon a couple of times with both --save and -g variants. What am I doing wrong?
Where is that error being thrown? It looks like you're trying to use files in a relative position, not express in node_modules. Does your project have a lib folder? Are you uploading it as well?
You can uninstall the global express with npm uninstall -g express. Delete your node_modules folder and start fresh with npm install and npm start. Does it run locally?

Heroku with React and nodemailer build failing

Im having issues getting my build on heroku to work. Heroku is saying the build succeeded but when I pull up the page I get the Application Error page.
Here is my package.JSON for the React
{
"name": "cloudveilheli",
"version": "0.1.0",
"private": true,
"proxy": "http://localhost:3001",
"dependencies": {
"axios": "^0.18.0",
"body-parser": "^1.18.3",
"concurrently": "^3.5.1",
"express": "^4.16.3",
"firebase": "^4.8.1",
"moment": "^2.22.1",
"nodemailer": "^4.6.5",
"nodemon": "^1.17.5",
"re-base": "^3.2.1",
"react": "^16.2.0",
"react-dom": "^16.2.0",
"react-router": "^4.2.0",
"react-router-dom": "^4.2.2"
},
"devDependencies": {
"node-sass": "^4.7.2",
"react-scripts": "1.0.17",
"redux": "^3.7.2",
"sass-loader": "^6.0.6",
"webpack": "^3.10.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}
and for the node.js
{
"name": "cloudveilheli",
"version": "0.1.0",
"private": true,
"proxy": "http://localhost:3001",
"dependencies": {
"axios": "^0.18.0",
"body-parser": "^1.18.3",
"concurrently": "^3.5.1",
"express": "^4.16.3",
"firebase": "^4.8.1",
"moment": "^2.22.1",
"nodemailer": "^4.6.5",
"nodemon": "^1.17.5",
"re-base": "^3.2.1",
"react": "^16.2.0",
"react-dom": "^16.2.0",
"react-router": "^4.2.0",
"react-router-dom": "^4.2.2"
},
"devDependencies": {
"node-sass": "^4.7.2",
"react-scripts": "1.0.17",
"redux": "^3.7.2",
"sass-loader": "^6.0.6",
"webpack": "^3.10.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}
In the logs, I am getting an error that react-scripts are failing in the Heroku build process. The node and the react are getting fired but it fails soon after that.
And here are the heroku logs
2018-06-13T12:56:17.879178+00:00 app[web.1]: [1] sh: 1: react-scripts: not found
2018-06-13T12:56:17.910185+00:00 app[web.1]: [1] npm ERR! file sh
2018-06-13T12:56:17.910189+00:00 app[web.1]: [1] npm ERR! code ELIFECYCLE
2018-06-13T12:56:17.912160+00:00 app[web.1]: [1] npm ERR! errno ENOENT
2018-06-13T12:56:17.913985+00:00 app[web.1]: [1] npm ERR! syscall spawn
2018-06-13T12:56:17.922554+00:00 app[web.1]: [1] npm ERR! cloudveilheli#0.1.0 start: `react-scripts start`
2018-06-13T12:56:17.927487+00:00 app[web.1]: [1] npm ERR! spawn ENOENT
2018-06-13T12:56:17.928818+00:00 app[web.1]: [1] npm ERR!
2018-06-13T12:56:17.932398+00:00 app[web.1]: [1] npm ERR! Failed at the cloudveilheli#0.1.0 start script.
2018-06-13T12:56:17.932401+00:00 app[web.1]: [1] npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2018-06-13T12:56:17.967183+00:00 app[web.1]: [1] npm WARN Local package.json exists, but node_modules missing, did you mean to install?
2018-06-13T12:56:17.968219+00:00 app[web.1]: [1]
2018-06-13T12:56:17.968222+00:00 app[web.1]: [1] npm ERR! A complete log of this run can be found in:
2018-06-13T12:56:17.968224+00:00 app[web.1]: [1] npm ERR! /app/.npm/_logs/2018-06-13T12_56_17_935Z-debug.log
2018-06-13T12:56:17.992492+00:00 app[web.1]: [1] npm ERR! code ELIFECYCLE
2018-06-13T12:56:17.992495+00:00 app[web.1]: [1] npm ERR! errno 1
2018-06-13T12:56:17.996672+00:00 app[web.1]: [1] npm ERR! bluebirdheliapp#1.0.0 client: `npm run start --prefix cloudveil_heli_app`
2018-06-13T12:56:17.999397+00:00 app[web.1]: [1] npm ERR! Exit status 1
2018-06-13T12:56:18.004427+00:00 app[web.1]: [1] npm ERR!
2018-06-13T12:56:18.004430+00:00 app[web.1]: [1] npm ERR! Failed at the bluebirdheliapp#1.0.0 client script.
2018-06-13T12:56:18.004432+00:00 app[web.1]: [1] npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2018-06-13T12:56:18.021046+00:00 app[web.1]: [1]
2018-06-13T12:56:18.021050+00:00 app[web.1]: [1] npm ERR! A complete log of this run can be found in:
2018-06-13T12:56:18.021052+00:00 app[web.1]: [1] npm ERR! /app/.npm/_logs/2018-06-13T12_56_18_005Z-debug.log
2018-06-13T12:56:18.046560+00:00 app[web.1]: [1] npm run client exited with code 1
while you push your app to heroku
first it runs npm install
later it runs npm start
so we have to declare in package.json what to run after npm install is completed and what npm start need to do.
update you package.json with:
{
"name": "cloudveilheli",
"version": "0.1.0",
"private": true,
"proxy": "http://localhost:3001",
"scripts": {
"start": "node server.js",
"postinstall": "npm start build "
},
"dependencies": {
"axios": "^0.18.0",
"body-parser": "^1.18.3",
where postinstall works after the npminstall is completed
and create a server.js file like this:
const express = require('express');
const app = express();
app.use(express.static(__dirname + '/dist'));
app.all('*', (req, res) => {
res.status(200).sendFile(__dirname + '/dist/index.html');
});
app.listen(process.env.PORT || 8080);
at dist/index.html give where index.html created in react
as i dont know react

Resources