How to Set up the Environment for Advanced Node and Express

Tell us what’s happening:
Passing the challenge: “Set up the Environment” was really hectic and almost took my whole time. Fortunately, I passed it after so many trials and searching.

Here are some tips to help you pass:

  1. Make sure that you opened the new glitch provided for the challenge.

  2. Add the code below to your server.js

const io = require("socket.io")(http);
  1. Add the code below to your client.js
/*global io*/
var socket = io();
  1. Do the code below:
onst client = new mongo(process.env.DATABASE, {useNewUrlParser: true, useUnifiedTopology: true});
client.connect(err => {
  const db = client.db("data base name"); //add your database name.
//you can find your data base name in your .env, it is stored as <dbname>. change and remove the <> and add the name you desire
    if(err) console.log('Database error: ' + err);
  
    auth(app, db);
    routes(app, db);
      
    http.listen(process.env.PORT || 3000);

  
    //start socket.io code  
 io.on('connection', socket => {
  console.log('A user has connected');
});

  1. Make sure you handle the error

Cannot read property ‘0’ of undefined
by doing the following:

photo: profile.photos ? profile.photos[0].value : "no profile"
email: profile.email ? profile.emails[0].value : "no email"

well, that should help you!

:smiling_face_with_three_hearts:

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36.

Challenge: Set up the Environment

Link to the challenge: