Advanced Node and Express - Implement the Serialization of a Passport User

Tell us what’s happening:

I’m getting the following error when I run the code, even after doing a copy-paste from the solution/guide. I have the MongoDB set up and configured with 0.0.0.0/0 in the Access List Entry, and set MONGO_URI to my database’s connection string (‘mongodb+srv://user1:dummypw@cluster0.m8kv5qy.mongodb.net/?retryWrites=true&w=majority’) in the sample.env file. The format of the string matches what is shown in the lesson, so there shouldn’t be any issues parsing, but this is the error:

fcc-advanced-node-and-express@0.0.1 start
node server.js

Listening on port 3000
MongoParseError: URI malformed, cannot be parsed
at parseConnectionString (/home/runner/boilerplate-advancednode/node_modules/mongodb/lib/core/uri_parser.js:580:21)
at connect (/home/runner/boilerplate-advancednode/node_modules/mongodb/lib/operations/connect.js:283:3)
at /home/runner/boilerplate-advancednode/node_modules/mongodb/lib/mongo_client.js:284:5
at maybePromise (/home/runner/boilerplate-advancednode/node_modules/mongodb/lib/utils.js:692:3)
at MongoClient.connect (/home/runner/boilerplate-advancednode/node_modules/mongodb/lib/mongo_client.js:280:10)
at main (/home/runner/boilerplate-advancednode/connection.js:11:22)
at Object. (/home/runner/boilerplate-advancednode/server.js:30:1)
at Module._compile (node:internal/modules/cjs/loader:1257:14)
at Module._extensions…js (node:internal/modules/cjs/loader:1311:10)
at Module.load (node:internal/modules/cjs/loader:1115:32)
TypeError: Secret string must be provided.
at exports.sign (/home/runner/boilerplate-advancednode/node_modules/cookie-signature/index.js:18:40)
at setcookie (/home/runner/boilerplate-advancednode/node_modules/express-session/index.js:656:33)
at ServerResponse. (/home/runner/boilerplate-advancednode/node_modules/express-session/index.js:243:7)
at ServerResponse.writeHead (/home/runner/boilerplate-advancednode/node_modules/on-headers/index.js:35:16)
at ServerResponse._implicitHeader (node:_http_server:335:8)
at writetop (/home/runner/boilerplate-advancednode/node_modules/express-session/index.js:276:15)
at ServerResponse.end (/home/runner/boilerplate-advancednode/node_modules/express-session/index.js:343:16)
at ServerResponse.send (/home/runner/boilerplate-advancednode/node_modules/express/lib/response.js:221:10)
at done (/home/runner/boilerplate-advancednode/node_modules/express/lib/response.js:1013:10)
at exports.renderFile (/home/runner/boilerplate-advancednode/node_modules/pug/lib/index.js:448:12)
/home/runner/boilerplate-advancednode/node_modules/cookie-signature/index.js:18
if (‘string’ != typeof secret) throw new TypeError(“Secret string must be provided.”);
^

TypeError: Secret string must be provided.
at exports.sign (/home/runner/boilerplate-advancednode/node_modules/cookie-signature/index.js:18:40)
at setcookie (/home/runner/boilerplate-advancednode/node_modules/express-session/index.js:656:33)
at ServerResponse. (/home/runner/boilerplate-advancednode/node_modules/express-session/index.js:243:7)
at ServerResponse.writeHead (/home/runner/boilerplate-advancednode/node_modules/on-headers/index.js:35:16)
at ServerResponse._implicitHeader (node:http_server:335:8)
at write
(node:_http_outgoing:919:9)
at ServerResponse.write (node:_http_outgoing:838:15)
at ReadStream.ondata (node:internal/streams/readable:774:22)
at ReadStream.emit (node:events:511:28)
at addChunk (node:internal/streams/readable:332:12)

Node.js v20.3.1

Your project link(s)

solution: boilerplate-advancednode - Replit

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36

Challenge Information:

Advanced Node and Express - Implement the Serialization of a Passport User

You can’t use a .env file when you’re on replit. If you store anything in a .env file on replit it will be publicly visible and won’t work as intended either. Instead, you should be using the Secrets tab to store your environment variables.

EDIT: You can still access them in the normal way, using process.env.VARIABLE_NAME.

Thanks, I’m no longer getting the parsing error. However, I’m now getting a different error:
TypeError: Cannot read properties of null (reading ‘split’)

Hmmm, I’m not sure why you’re getting that error. I forked your code and it passed for me. I can’t seem to replicate your error.

EDIT: Ah, did you put quotation marks around your MONGO_URI string? Remove them.

That was the problem, it works now. Thanks!

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