1

I have been following along to Acadamind's NodeJS / Express / MongoDb-build a shopping cart tutorial on youtube and everything was going fine until I restarted the mongodb server when I wanted to update a product item.

Before this change, I would write npm start and the code would run smoothly, but now I am given a response of:

(node:49784) UnhandledPromiseRejectionWarning: Error: connect 
ECONNREFUSED 127.0.0.1:27017
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1097:14)
(node:49784) UnhandledPromiseRejectionWarning: Unhandled promise 
rejection. This error originated either by throwing inside of an async    
function without a catch block, or by rejecting a promise which was not 
handled with .catch(). (rejection id: 1)
(node:49784) [DEP0018] DeprecationWarning: Unhandled promise rejections 
are deprecated. In the future, promise rejections that are not handled 
will terminate the Node.js process with a non-zero exit code.

I am new to node.js and am not sure why this is occuring when I believe all i did was change a product item in my seed folder.

Here is the link to my github repository:clone my git hub "shopping-cart" repository here

Note: since this is my first node.js project that I am having problems with, is this the correct format to ask for help due to the larger nature or the project.

Thanks for any feedback!!!

Tyler Morales
  • 1,440
  • 2
  • 19
  • 56
  • Oh, most likely mongod server isn't running. If your app contains mongo client code, and the mongod server isn't running, the connection will fail. – RichS Apr 30 '19 at 03:23
  • On linux you'd run something like: `sudo service mongod start`. On windows, you'd find your mongod folder, find the `mongod.exe` file and run it. That should solve the connection problem. – RichS Apr 30 '19 at 03:24
  • So I have to have the mongo server running first? I tried that as well, however, I got another error that resulted in the server shutting down. Check out my link if you haven't already to read the full error message under the README file. – Tyler Morales Apr 30 '19 at 03:26
  • I'm running linux on a Mac. I'll try the sudo command – Tyler Morales Apr 30 '19 at 03:26
  • Yeah, mongod running first is needed. It is expected to listen on 127.0.0.1:27017 by default. So, when an app (client) tries to connect to that address but can't, it'll throw the ECONNREFUSED error (the code means "connection refused error") – RichS Apr 30 '19 at 03:27
  • 1
    And then to make sure it is indeed running, you gotta run: `sudo service mongod status`. It should say "Active (Running)". If it says failed or error, the issue is with mongod (possibly config), not your app. – RichS Apr 30 '19 at 03:29
  • 1
    I got it! Thanks for the help @RichS – Tyler Morales Apr 30 '19 at 03:29
  • @TylerMorales from your full error message in the link, its looks like mongo server is unable to start . Please refer the [link](https://stackoverflow.com/questions/42446931/mongodb-exception-in-initandlisten-20-attempted-to-create-a-lock-file-on-a-rea) – vinodk Apr 30 '19 at 03:32

1 Answers1

1

Mongod needs to be running before starting the app: sudo service mongod start

Status check: sudo service mongod status

(should show Active (running))

RichS
  • 913
  • 4
  • 12