I created this repository to help debug an issue I reported on StackOverflow. The issue I'm having is that the .then()
method is not being executed when I call the mongoose findOne()
method, which seems not to be returning a es2015 Promise
. More details of the issue can be found on the StackOverflow Question.
- node v8.11.1
- MongoDB shell version v4.0.1
- MongoDB server version: 4.0.1
To reproduce this issue you need to first install and setup MongoDB and then Node.js app of this repository.
- Install the MOngoDB community server from their download centre.
- Launch the MongoDB server with the
mongod
command in your terminal. (You can stop it by pressing CTRL + C) - IN a new terminal window connect to the MongoDB via it's
mongo
shell command. - Create a database with following commands...
use devconnector
db.testData.insert( { Description : "Initial document used to create database" } )
Enter the command below into your terminal to download the repository from github, install and launch it.
git clone https://github.com/bradtraversy/devconnector.git
cd devconnector
npm install
npm run debug
You should now be able to reproduce the issue.
Open your browser at http://localhost:5000/ and in it's console enter...
fetch("http://localhost:5000/api/users/register", {
method: "POST",
body: JSON.stringify({
name: "holly",
email: "holly@mail.com",
password: "holly123"
}),
headers: {
"Content-type": "application/json; charset=UTF-8"
}
})
.then(response => response.json())
.then(json => console.log(json));
If you use the nodeJS debugger you will see that the code does not execute line 29 of routes/api/users.js.