Nodemon crashed while setting up express server - node.js

while setting up an express server, I tried to run it, bt is showing an error, the exact phrase I typed on the terminal is (npm run dev), I checked whether my port is already under work or if there same name file in my laptop and whether my package.json is in the same folder of my server.js .. nothing is working, being a newbie it's my first project. I would be most grateful if the community can help me.
server.js window - showing error
package.json code

You're trying to require express and your package.json doesn't include it so I assume you don't have it installed
npm install express should fixt it

Related

how to fix "Error: Cannot find module '/home/container/index.js'", I've tried everything

So the host that I use for my discord bot died so I downloaded all the code and tried hosting it on my PC. But I get the following error.
Error: Cannot find module '/home/container/index.js
I've tried everything I can:
updated nodejs
reinstalled all my packages
Changed package.json
How can I fix this?
Cannot find module means you are trying to run non-existent file.
Ensure there is index.js in your working directory. If not,
Use cd to go to the directory where it is (usually it's src near the package.json)
Run node ./index.js
Many time people have just the problem of command line to run file,
as windows and linux have
different syntax to run .js file
i.e. node ./index.js for linux
and node .\index.js for windows

My nodemon app crashed after updating npm. What to do?

I went ahead and used npm update in my terminal(hyper) and when I tried to restart my app.js server, I got an error stating
[nodemon] app crashed - waiting for file changes before starting...
I thought I needed to use this command (npm update) in order to update my node modules, but then for some reason, some modules got deleted. ("Error: Cannot find module 'parseurl'"). I'm still a newbie to development and have no clue where to go from here. What to do?
Here's a screenshot of the error in my terminal.
screenshot of error
Nodemon tried to start the server, but it won't start successfully if it can't find the module you are referencing. Try reinstalling "parseurl" npm i parseurl and make sure the path to the module is correct. Once you have done that, the server should start successfully pending any other issues.

Heroku cannot find ./node_modules/.bin/forever in Procfile of Yeoman MEAN app

I've been trying to get a Yeoman generated MEAN.js app deployed to Heroku for the best part of a day without much luck.
I've carefully gone through all the steps and am pretty sure I've done everything correctly according to documentation.
After several times going through and ensuring the database is configured correctly with heroku config, removing the public/dist folder from the .gitignore, running grunt build, setting NODE_ENV=production, and running a successful Heroku build the app just continuously shows the very unhelpful Heroku Application Error page.
Upon checking the heroku logs the only thing I can find is this:
bash: ./node_modules/.bin/forever: No such file or directory
Process exited with status 127
Which clearly refers to the Procfile that contains this single line and is where the app is supposed to start from.
web: ./node_modules/.bin/forever -m 5 server.js
There is a server.jsin the root of the project so I tried modifying the Procfile to a standard web: node server.js but that doesn't fix it and I am not comfortable messing with the default Yeoman configuration.
The ./node_modules/.bin/forever is of course there where it is supposed to be. But it obviously isn't showing up or cannot be located in the live Heroku build. If anyone knows what the problem is here and how to fix it I'd much appreciate the help! Cheers!
This happened to me after I upgraded my nodejs, I can't figure out why exactly it is happening, but here is my fix for it asap,
When I ran heroku run ls node_modules/.bin/
I could not find forever there. So I installed and save it to my dependencies by running npm install forever --save
On running heroku run ls node_modules/.bin/ again, it was there and my app runs fine.
I'll sure update this soon, once I figure what exactly led to it.

Error when starting Nodemon on my server.js file (Nodejs)

I recently started getting an error in my terminal when I start nodemon on my server.js file within my directory. Here is a picture below
Here is the error.
dyld: lazy symbol binding failed: Symbol not found: _node_module_register
Referenced from: /Users/dan/nodeStuff/crm-test/node_modules/mongoose/node_modules/mongodb/node_modules/bson/build/Release/bson.node
Expected in: dynamic lookup
Not sure what the issue is. I did a brew update and also made sure my port was correct.
For anyone else who stumbles by this problem, I had the same issue when trying to start my server with nodemon.
For me, the problem was I was still using an older version of node with nvm. I switched back to the version appropriate for my application and problem solved!
Did you try running node server.js?
Maybe it's not nodemon.
I've looked around and I did a npm rebuild which helped. When I start nodemon server.js or node server.js it tells me that one of the packages I was using is depreciated, I'm guessing that's what threw the error. Not sure why body-parser is depreciated.

I cannot use npm start to start an express server on windows

I am new to node. I am trying to run an express server. I get no errors when installing express but when i run npm start or node app (as all the beginner tutorials point) nothing seems to be happening. The only way i can start the server is by typing node /bin/www. My operating system is Windows. Any advice?
The Express scaffold script generates a package.json file with a start script field that points to the app.js file it also created. Since Express 4 was released the scaffold generator script has been moved to its own package. https://github.com/expressjs/generator
All npm start does is look in the package.json file for a starting script to pass to node. You can see this in the documentation.
Running npm start with a package.json like this:
"scripts": {
"start": "app.js"
}
Is exactly equivalent to running node app.js.
I managed to solve my issue by changing the code page of cmd-dos. By using chcp 850 or chcp 65001 in cmd thus changing codepage to latin - utf8 the issue is gone.

Resources