Node - Cannot read property split of null

Kevin, good afternoon!

I’m getting the same error here.

Could you try to help me?

Here is the link to replit: https://replit.com/@aleperrod/boilerplate-mongomongoose#myApp.js.

I split this out to a new topic. It’s difficult because we can’t run your DB and don’t have your env variables. So, you’re going to have to do some detective work on your own. I also don’t do a lot of work in the MEN stack.

I don’t see where you’re trying to split anything so I’m guess it is in some package. Some package is getting a null where it expects a string.

My first guess is to start with the connect.

mongoose.connect(process.env.MONGO_URI,{ useNewUrlParser: true})

First, log out process.env.MONGO_URI to confirm what that value is.

Doing a google search for that error found this post. I cannot stress enough how important “googling stuff” is to a developer. It is often the first step.

If that is not the issue, at least try to figure out where the error is happening. Is that the complete error? There is no other info?

Going further, I would put in log statements to try to figure out exactly where it is happening.

Kevin,

I’ve finnaly found the solution.

Now, it seems to me that the lesson instructions of “Install and Set Up Mongoose” are misleading.

In its closing paragraph, one can read:
" Create a .env file and add a MONGO_URI variable to it. Its value should be your MongoDB Atlas database URI. Be sure to surround the URI with single or double quotes…"

But, it was just after removing the quotes from around the MONGO_URI value that I was able to pass the test.

In fact, earlier in this lessons series, we have learned that .env variable values should not be surrounded with quotes. But, as any good student, I was trying to follow straight the teacher instructions.

1 Like

That’s a good catch. I’ll check if there is a bug for this.

It still hasn’t been fixed, is there a way I could fix it myself or create an issue somewhere?

Sorry, I probably didn’t get to this as I was in a job search. You can check here:

See if anyone has raised the issue and if not, make a ticket yourself. It’s a good way to start building some github cred.

Having the connection string inside quotes is only an issue with Replit secrets because it automatically adds the quotes so you end up with a double-quoted string. You can tell if you click the “Open raw editor” button under the secrets.

You would get the same error if you double-quoted the connection string in the .env file.

We should probably add a note about it, the challenge is also missing the note about using Replit secrets found in the basic express .env challenge.

I made a PR.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.