Beginner alert! I'm using express.js with mongodb and I set up a mongodb server in a terminal window through
mongod -dbpath *path name*
I accidentally closed the text editor without killing the terminal window that had the server running, so when I tried to set up a new server somewhere else it said that there was already a server running and wouldn't let me start another. I can't figure out how to close the last server because I can't go back to the terminal that it was running from and kill the terminal with control+c.
Is there a way to kill all mongodb servers from outside the terminal window that it's running?
Try this command
mongod --dbpath /path/to/your/db --shutdown
You can follow this official page for more info -
https://docs.mongodb.com/manual/tutorial/manage-mongodb-processes/
Related
I am making an app on Node.js and trying to connect to MongoDB via mongoose. When I run it, in cmd it shows "connected to MongoDB database", but this is what it shows when I run mongo. It doesn't say connected
Mongo connection status
Also, when I try to connect MongoDB compass to localhost:27017, it shows the error " read ECONNRESET".
So clearly, for some reason, my MongoDB is not connected to the localhost. Can someone help me out? here is my mongoose connection code in app.js.
App.js Mongoose connection code
Can you check your mongod.conf file to see the port the server is set to run on.If on linux and running as a service use systemctl status mongod to ensure the process is running. Hope it helps.
Maybe you should run the command- " mongod " in another window and check.
If it's not connecting, simply go in that path:
C:\Program Files\MongoDB\Server\5.0\bin
and click shift + right, open window PowerShell or any other command prompt, and then type mongod like that:
PS C:\Program Files\MongoDB\Server\5.0\bin> mongod
and connect to it again.
Just followed these simple steps:
Type here to search -- Services -- Click on that
Find -- MongoDB Server(MongoDB) -- Click on that
On the left site of window You will see -- Start-- link. Click on that,
and your problem is solved.
I'm using MongoDB, Node.js and Ubuntu 16.04 OS.
I set up MongoDB database from mongo CLI. I also communicated with it using node.js's mongodb library.
I thought I should start the database first (and start listening on the port) with mongod command.
But now I didn't start the database with mongod and still my communication from node.js towards database works fine.
Should mongod be run prior to communication with database, or is mongod process still alive from restart (I cannot find it listed in processes), or maybe my node.js code stores data in local variables that I haven't notice?
check on your ubuntu:
ps aux | grep mongod
if you see a process then it's running.
You can also write: top
With top you will see the current status of your system along with all the processes running.
With ps au you only see all process that are not attached to your TTY
I am making my first app in node js and i uploaded it on server. I have a terminal where I am running a session containing two panes, one for running mongod and second for running node app.js . Now both of them run as long as I keep it running. But how can we make sure after quitting the window it keeps running both of them mongod and node. I am using tmux, mongodb, express and node.
I tried tmux detach and tmux attach. They work. But for tmux detach first i have to quit the current command by ctrl + c and then i would be able to run tmux detach. Am I doing something wrong? Please Help
I presume this is for a development environment and not production. In production, keeping something running "forever" makes using a process supervisor to make sure it is restarted when it crashes.
In development, you can use <Prefix>-d to detach without cancelling the current command. The Prefix for Tmux is Control-B by default.
I'm new to aws and recently I have been able to install node, mongod and also, FTPed project file to the server.
For mongodb,
I'm doing mongo in a separate terminal tab and starting service in another tab. I want to know how can I keep the mongo service running.
For node app,
Right now i'm doing node app in the server. How can I keep it alive too ?
Now the problem, is I open the browser with publicip:portno but nothing happens. How can I locate app and run it in the browser.
my app structure is
/
node
mongo
server.js and app related files
Using the Linux/Unix nohup command allows you to start commands that ignore the signals associated with the controlling terminal process terminating (SIGHUP). Adding the & to the command allows that command to run in the background and sending the output to /dev/null will ensure that your disk does not fill up with unnecessary log output. Here are some commands that should work:
nohup mongod >/dev/null &
node server.js >/dev/null &
This is more of a Linux/Unix command line issue I think. You can use the node module called forever to run your Node.js process in the background easily.
npm install -g forever
forever start YourScript.js
You can place an & at the end of the mongod command to place it in the background.
Ensure that in your node app you have the command app.listen("port number");
This is the "port number" that you should be using in your browser to render the page with the elastic IP from your AWS instance. Make sure that your elastic IP is configured to accept inbound requests.
To keep the service/app running in the background you can run the screen command then launch ur app/service (e.g. mongod OR node app.js). In the same terminal that your app is running press control + a + d, you should see
(detached)
printed on your screen.
This should keep your app/service running in the background.
This is probably a simple question but I can't find a clear answer anywhere. I am trying Hello World on node.js. I have a node.js server running on port 8000 of the localhost, turned on via the command line e.g. "node helloworld.js". Helloworld.js runs fine via localhost:8000. Now when I try turn on another server on port 8000 though I get the error "listen EADDRINUSE" because the first server is still running. So how do I turn off the first node server?
Just kill the process by doing ctrl-c...
If you still have the original terminal in which you run the Nodejs server, then simply press ctrl + C can kill the process.
However, if you lost the terminal, then you can open another terminal and run taskkill /F /IM node.exe. (/F to force the kill, /IM to specify which script you want to kill). Note that the command would kill every node server running.
If you no longer have access to your terminal, then go to your task manager on Windows or 'Force Quit' on Mac and end the 'Node.Js...' process.
This is the cleanest way to do it (if no terminal window), in my opinion.