Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Jun 19 2020 20:05
    @krisb1220 banned @Gastony
  • May 14 2020 22:39
    @bjorno43 banned @minitechtips_twitter
  • May 14 2020 22:38
    @bjorno43 banned @real-action
  • Feb 01 2020 00:26
    @bjorno43 banned @Ndoua
  • Jan 07 2020 03:10
    @bjorno43 banned @doctor-sam
  • Aug 17 2019 09:32
    User @bjorno43 unbanned @linkin-park
  • Aug 17 2019 01:43
    @bjorno43 banned @linkin-park
  • Jun 20 2019 21:20
    @bjorno43 banned @shenerd140
  • May 10 2019 09:13
    @bjorno43 banned @zhaokunhaoa
  • Apr 27 2019 19:47
    @mstellaluna banned @zhonghuacx
  • Apr 25 2019 17:12
    @mstellaluna banned @cmal
  • Jan 08 2019 22:00
    @mstellaluna banned @dertiuss323
  • Dec 15 2018 23:36
    @mstellaluna banned @18835579411
  • Dec 13 2018 23:57
    @mstellaluna banned @brandon6190
  • Oct 12 2018 05:50
    @bjorno43 banned @NACH74
  • Oct 05 2018 23:02
    @mstellaluna banned @JomoPipi
  • Sep 16 2018 12:21
    @bjorno43 banned @yash-kedia
  • Sep 16 2018 12:16
    @bjorno43 banned @vnikifirov
  • Sep 05 2018 08:13
    User @bjorno43 unbanned @androuino
  • Sep 05 2018 07:38
    @bjorno43 banned @androuino
Richard Sithole
@Sliqric7053
Makes sense. Thanks @alpox 👌🏽
Rahul Yedida
@yrahul3910

I'm frustrated after an hour of debugging this, maybe you guys can help. I have a file to interact with my MongoDB, and it has:

exports.getUserDetails = async username => {
    const client = new MongoClient(uri, { useNewUrlParser: true });
    client.connect(async err => {
        if (err) throw err;

        const collection = client.db('db').collection('users');
        const result = await collection.findOne({ username });

        return result;
    });
};

and I call it as:

const details = await dbUtils.getUserDetails(username);
console.log(`got ${ details}`);  // prints "got undefined"
I have no idea why I'm getting undefined. If after the last await in my getUserDetails function I add a console.log, it prints out the object
alpox
@alpox
@yrahul3910 you dont return anything from getUserDetails you only return from the callback to connect
Rahul Yedida
@yrahul3910
Ahh. Damn. Thanks!
habibaatify
@habibatify_twitter
Hello
What am u missing in this code ?
habibaatify
@habibatify_twitter
Hi
Kelechi Chinaka
@ke1echi
:wave: everyone
Jason Luboff
@JLuboff
Hello
Kelechi Chinaka
@ke1echi
Good to see you @JLuboff
Been a while
Jason Luboff
@JLuboff
Likewise, hope you've been doing well
Kelechi Chinaka
@ke1echi
Yea always trying my best
The past year got me writing swift(iOS)
Just trying to find my backend footing again lol
What have you been up to lately? @JLuboff
Jason Luboff
@JLuboff
Nice man. I've been crazy busy at working. Updating existing apps (both my own and the prior programmers), training a new guy, etc
Kelechi Chinaka
@ke1echi
app.post('/register', async (req, res) => {  
  const { error } = schema.validate(req.body);
  if (error) {
    return res.status(401).json({
      status: false,
      message: error.details[0].message
    });
  }

  // Check if user is already in DB
  const userEmailExist = await User.findOne({ email: req.body.email });
  if (userEmailExist) {
    return res.status(409).json({
      status: false,
      message: "Email already exists"
    });
  }

  // Hash user password
  const salt = await bcrypt.genSalt(10);
  const hashedPassword = await bcrypt.hash(req.body.password, salt);

  // Create new user and save to MongoDB
  const user = new User({
    name: req.body.name,
    email: req.body.email,
    emailToken: crypto.randomBytes(64).toString('hex'),
    password: hashedPassword
  });

  const msg = {
    to: user.email, // Change to your recipient
    from: 'mrkelechichinaka@gmail.com', // Change to your verified sender
    subject: 'Account Verification Token',
    text: `
      Hello, thanks for registering on our site.
      Please copy and paste the address below to verify your account.
    `,
    html: `
      <h1>Hello,</h1>
      <p>Thanks for registering on our site.</p>
      <p>Please click the link below to verify your account.</p>
    `
  }

  try {
    await user.save();
    await sgMail.send(msg)
    res.send(`Email sent successfully to ${user.email}`);
    res.redirect('/');
  } catch (error) {    
    console.log(error);
    res.send(`Something went wrong. Please contact us noreply@gmail.com`);
    res.redirect('/');
  }
});
I'm trying to implement email verification signup, above is my code
it saves to the db successfully, sends mail to user. then server crashes
Jason Luboff
@JLuboff
Whats the error when it crashes
Kelechi Chinaka
@ke1echi
throws me this error =>Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
Jason Luboff
@JLuboff
Oh... its becuase you have res.send followed by a redirect...you can't do that as send is sending the http response
Kelechi Chinaka
@ke1echi
ok. so i cant do both?
Jason Luboff
@JLuboff
No
Kelechi Chinaka
@ke1echi
oh wow and I've been looking at this screen wondering whats go wrong
thanks @JLuboff
A_step_below_classy
@kbventures
Hey guys. I've just finished the url shortener. I couldn't get it to work on repl or glitch but it works locally and also on heroku. Is this sufficient to past the challenge?(I intend to refactor it). https://url-shortener-micro-service.herokuapp.com/ github: https://github.com/kbventures/URL-Shortener-Microservice
Camper94
@Camper94
hi
TheKid-byte
@TheKid-byte
anyone online??
Tunde Oretade
@tundeiness

hi guys I kinda need urgent help right now. I have an assignment but currently I have a little challenge with connecting parts. Here is the task

a web app which logs calculations as they happen and shares those calculations with everyone connected to the app.

currently I have implemented a calculator using React and it works perfectly I have also setup a server using node, express and socket.io my current challenge is how to get inputs from the calculator to be displayed in a form of chats which is the socket.io and node setup. Any input is appreciated.

Christopher McCormack
@cmccormack
Hello! If you are new here and want to join the conversation, please head over to the freeCodeCamp Discord channel! https://www.freecodecamp.org/news/freecodecamp-discord-chat-room-server/
Tunde Oretade
@tundeiness

hi guys i need help with this:

filterData = () => {
      const {
        enrollee, id,
      } = this.state;
      const newData = enrollee.filter(data => {
        if (data.id === id) {
          return data;
        }
        return null;
      });

      this.setState({ singleUser: newData });
    }

what am I doing wrong?

Jagdish Parihar
@jatin510
Hi. I want to design a project using MVC in express.
Can anyone help me with the design I should follow for that.
I want to know. What should be the folder structure look like
so that, it can be easily modifiable in the future
wordlesspirate
@wordlesspirate
have you tried using express-generator, @jatin510? take a look here: https://expressjs.com/en/starter/generator.html
Jagdish Parihar
@jatin510
thanks @wordlesspirate :)
Cesar Gomez
@zootechdrum
Hey everyone, I could use a little help understanding an NPM package that was used by Brad Traversy(Udemy Instructor)

It seems simple enough to put into practice, however I am confused on how the function is being called. Here is the meat of the file.

const asyncUtil = fn =>
function asyncUtilWrap(...args) {
  const fnReturn = fn(...args)
  const next = args[args.length-1]
  return Promise.resolve(fnReturn).catch(next)

}

Here is an example of what its use is
const asyncHandler = require('express-async-handler')

express.get('/', asyncHandler(async (req, res, next) => {
    const bar = await foo.findAll();
    res.send(bar)
}))

Without express-async-handler

express.get('/',(req, res, next) => {
    foo.findAll()
    .then ( bar => {
       res.send(bar)
     } )
    .catch(next); // error passed on to the error handling route
})

I don't understand when asyncUtilWrap gets called.
I understand that asyncUtil accepts a function as an argument. In most cases it will be the callback from express. Then in the example we query are databases for all the items. At what point does asuncUtilWrap take over. By the name of it it sounds like it wraps our original function. However I have tried a few console messages within the function and I can't get it to fire off. Any help would be appreciated . Thank you!

Matthew
@ChaplainsBud
hi
Corey Lewis
@cursiv3
@zootechdrum is asyncUtilWrap exported from that file? or is it used in another func in that file that is exported?\
asyncUtil is creating a closure, so the function passed to it will "initialize" the func, returning asyncUtilWrap with whatever fn was passed to it; but it'd have to invoked
did you place a console.log inside the node_modules file? If that's the case and you didn't see anything, it might be because you put the log into the unbuilt file rather than the built file; you'd need to find the built file usually in like lib which will be the transpiled code actually being used from the packag
Corey Lewis
@cursiv3
so looks like express.get initializes asyncHandler with the callback you give it, then when the route gets hit I'd expect that asyncUtilWrap to fire
Jake
@JakeDVirus
do i need/should learn sql if i'm planning to learn/use graphql in the end?
Corey Lewis
@cursiv3
@JakeDVirus graphql isnt a database, it's an alternative to REST database queries, you can use graphql with sql or NoSQL databases
divyajeetsingh
@divyajeetsingh
Hi , everyone
Zerka1982
@Zerka1982

I got a question please, I have built a react application with MongoDB. In the structure of my project I have 2 folders one is for the Front-end and the other for Backend. In order for me to see the actual result, I run nodemon server.js within the backend folder, and then I run on the project level npm start. My application is working perfectly.

My question to you guys, Would I face any issue if I deploy my project to Netlify ?

Zerka1982
@Zerka1982
Solved!
dmnkvd
@dmnkvd
Hi everyone! I have just finished building my VueJS (frontend) and Strapi (backend) project... In two main folders, "frontend", and "backend", each with their own NodeJS / yarn configurations. I am completely stuck trying to deploy it on cPanel with Namecheap... Currently, the Vue part runs on localhost:8080, and Strapi on localhost:1337; I have no idea what these URLs become once on the server?
buiphuking
@buiphuking_twitter
image.png

hi guys,
i code website using laravel,
i set up mysql is my first database, mongodb is my second database
my .env:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=source
DB_USERNAME=root
DB_PASSWORD=

DB_CONNECTION_SECOND=mongodb
DB_HOST_SECOND=127.0.0.1
DB_PORT_SECOND=27017
DB_DATABASE_SECOND=demo
DB_USERNAME_SECOND=null
DB_PASSWORD_SECOND=null
and i query builder, i get this error:
i have fixed everything i can, please help me

Ashref
@Asher2016
HI , i want to duplicate entitis but in same time i want to know the original entity of duplicated entities , does Someone have any idea ? thx :)