![]() ![]() Server started at port: 5000 Test app API endpoints using cURL You will see this on your terminal: node server/app.js To run our server, type the following command: node server/app.js bodyparse.json: It is used to parse formdata in POST requests into req.bodyobject.helmet: Like a real helmet, armours our API to prevent attacks.cors: It prevents cross-origin request errors.Run the following command: touch server/app.js It’s time to add entry-point to our backend. Now, we are done setting up our routes, controllers, and models. We now have our routes all defined, We are now going to create a function in routes/index.js that takes the Express.Router instanceĪnd paste code below to Creating server entry-point We now open up routes/article.js, and paste the following code: We will create an index route function that will export all routes(routes/article.jsand routes/user.js) in our app. Run the following commands:Īrticle.js will hold routes for our articles endpoint and user.js will hold routes for our users. We create some basic CRUD like get and set for handle User data Create Routes Let’s go through the functions to explain better what they do: They will host the images for us and use their image url to display our images on our frontend. We will use it to upload our article feature image. Note Cloudinary is an Image/Video service which handles media (Images, Videos) sharing seamlessly. We first imported our Article model, we defined earlier, then, we proceeded to import cloudinary. Looking at tthe above code, you can see we have CRUDy functions and helper functions: getArticle, addArticle, getAll, clapArticle, commentArticle. Open up controllers/, and paste the following code: Here, we will create our controller files: I'm Max Stoiber - the creator of react-boilerplate, one of the most popular react starter kits (10K+ stars on…Create Controllers Learn React.js, Redux & Immutable.js while building a weather app Now, make server/models/User.js to look like this: feature course We will be using two Schemas Article and User.Article represents articles and User represents users Note, we are using mongoose, a MongoDB connection utility. We will start by creating our database Schemas. Go ahead and scaffold the following folders and files: Models: This will hold all our app’s database Schemas and Models. ![]()
0 Comments
Leave a Reply. |