adrianhajdin / project_mern_memories

This is a code repository for the corresponding video tutorial. Using React, Node.js, Express & MongoDB you'll learn how to build a Full Stack MERN Application - from start to finish. The App is called "Memories" and it is a simple social media app that allows users to post interesting events that happened in their lives.
https://youtube.com/playlist?list=PL6QREj8te1P7VSwhrMf3D3Xt4V6_SRkhu
4.95k stars 1.83k forks source link

Having issues loading the posts on creating them? (Circular loader stuck) #161

Closed AbhayGupta01 closed 1 year ago

AbhayGupta01 commented 1 year ago

See if you are following the video and are stuck on the step where you fetch the posts from the database but only see a circular loader going on and on, then this is because there are some steps missing from the video (maybe adrian forget to add them). Now follow these steps: go to controller in server and paste this: `//updated code import PostMessage from '../models/postMessage.js'; export const getPosts = async (req, res) => { try{ const postMessages = await PostMessage.find();

    res.status(200).json(postMessages);
}
catch(error){
    res.status(404).json({message: error.message});
}

} export const createPost = async (req, res) => { const { title, message, selectedFile, creator, tags } = req.body;

const newPostMessage = new PostMessage({ title, message, selectedFile, creator, tags })

try {
    await newPostMessage.save();

    res.status(201).json(newPostMessage );
} catch (error) {
    res.status(409).json({ message: error.message });
}

} //end` this should fix your errors and if you are having a network connection error just to mongo atlas -> network access -> add ip address -> check the box to allow fetch from anywhere and save OR just type this 0.0.0.0 ip address and you are good to go.