Faker
Faker
KPCKevin Powell - Community
Created by Faker on 12/8/2024 in #back-end
Connect.sid in express using express-session
connect.sid in express session refreshes when I reload page, why... the id is same but just when timeout is reached, the connect.sid is destroyed but if I refresh page, it is regenerated, is that normal behaviour ?
3 replies
KPCKevin Powell - Community
Created by Faker on 12/8/2024 in #back-end
Cookies not stored in postman when we use the front-end
I'm testing user session using postman. When I use postman to log in, a session is created and a cookie is stored. When I try to use the front-end to login, the cookie is created but isn't stored in postman, is this normal ?
15 replies
KPCKevin Powell - Community
Created by Faker on 12/8/2024 in #back-end
Understanding sessions in express
Hello guys, sorry to disturb you all; I'm currently learning about managing sessions in express and I came across 2 properties: resave and saveUninitialized. I didn't understand these 2 properties; where and why do we use them? What does they do? From what I have understand, resave prevents the session from storing data for each request in our store (but what if we don't use a store? Like in my case; when is a store needed?) while saveUninitialized just makes sure that we create a cookie if we modify the request session
1 replies
KPCKevin Powell - Community
Created by Faker on 12/8/2024 in #front-end
Why image appears "pixelated" despite object-fit cover used
No description
16 replies
KPCKevin Powell - Community
Created by Faker on 12/7/2024 in #back-end
When creating a sign out route, should post or get request be used? why ?
Hello guys, sorry to disturb you all, I want to create a sign out route in my express server. I was reading a bit and saw that nowadays post request are used instead of get request which we used back in 2010. My question is why has this changed, why post is now used, I know the simple answer is "for security" but what exactly happens when using get or post to sign out a user, how post will handle it in a different way compared to get please
30 replies
KPCKevin Powell - Community
Created by Faker on 12/5/2024 in #back-end
Are there any free API to be consumed for a simple chatbot
Are there any free api that can be use to create a simple chatbot please... I was told the openai api should be paid, even if we are using the gpt 3.5 turbo model
15 replies
KPCKevin Powell - Community
Created by Faker on 12/5/2024 in #back-end
Bearer token vs API key
Hello guys, sorry to disturb you all; is there a difference between a bearer token and an API key? From what I have understand, both a bearer token and an API key is kind of an "access card" that grants us access.
60 replies
KPCKevin Powell - Community
Created by Faker on 12/5/2024 in #back-end
What is the purpose of API keys when it comes to third party apis
Hello guys, sorry to disturb you all; I started to learn the concept of APIs etc and I'm pretty conformtable with that term now especially the request-respond cycle. My question is, I saw that we have "API keys" what does that mean, when do we need them please. The idea of apis remain the same in the sense that it's just a request-respond cycle but what do we mean by "consume that api key" , then based on apis, we have documentations for specific one etc, I'm a bit confused here, how does it work, do we fetch the api from the back-end? Would really appreciate if someone can elaborate giving simple example please
19 replies
KPCKevin Powell - Community
Created by Faker on 12/1/2024 in #back-end
POST operation vs DELETE operation
Hello guys, sorry to disturb you all; I was just experimenting some CRUD operations in mongoDB and I needed to remove a particular thing from the database. What I did is that I send a POST request having in my req.body whatever thing I need to remove. The confusion that arise is that, notice that I want to DELETE something but I use a POST request; it works fine, the thing is we can use both POST or DELETE, what is the difference then please
37 replies
KPCKevin Powell - Community
Created by Faker on 11/30/2024 in #front-end
Can we use the DOMContentLoaded event inside an async function?
Hello guys, sorry to disturb you all; I tried to use the DOMContentLoaded event in an async function but it seems that the event isn't being executed, is there a reason for that please
6 replies
KPCKevin Powell - Community
Created by Faker on 11/30/2024 in #back-end
How to link a post created from the front-end to the back-end to handle comments
Hello guys, sorry to disturb you all; I need to store comments for posts in my project. My database, mongoDB, has a post collection and in that collection, I will have an array "comments" which will store the comments for that particular post. The problem is how do I identify the post from the front-end correspond to that post on my database? The idea I first have is to identify the post by its title. The thing is title is not necessarily unique, so there might be some conflicts here. Does anyone have any idea of how I should proceed please.
48 replies
KPCKevin Powell - Community
Created by Faker on 11/28/2024 in #front-end
Issues when building my main-content column for a social media website
No description
21 replies
KPCKevin Powell - Community
Created by Faker on 11/26/2024 in #back-end
Why did we use a .catch() rather than a catch() block while handling errors
Hello guys, can someone explain why in the following code, we use a .catch outside the function body that is when the function run is being called. Why don't we use a catch block directly after the try ? If we don't use a catch block inside, then what's the need of the try, we can remove it ? From what I have understand, this is why we might want to use a .catch() outside the function body rather than inside: we don't want the flow inside the function to stop every time there is an error with our return promises, instead of handling each error 1 at a time, let's just handle it at an upper level, that is when we call the function
async function run(username,password) {
try {
const database = client.db('socialMedia');
const users = database.collection('users');
const doc = {user : `${username}`, pwd : `${password}`};

const result = await users.insertOne(doc);
console.log(result);
}
finally {
await client.close();
}
}

run('username','secret')
.catch(console.dir);
async function run(username,password) {
try {
const database = client.db('socialMedia');
const users = database.collection('users');
const doc = {user : `${username}`, pwd : `${password}`};

const result = await users.insertOne(doc);
console.log(result);
}
finally {
await client.close();
}
}

run('username','secret')
.catch(console.dir);
7 replies
KPCKevin Powell - Community
Created by Faker on 11/25/2024 in #back-end
Why webpage refresh when we submit form with an image uploaded
Hello guys, I want a page to submit data without reloading. So I use the event.preventDefault() on my form and use the fetch API to send a request to my server. When I submit text fields only, like no image uploaded, I get the correct response and the web page isn't refresh. Now when I try to upload an image, I receive the response, a success response but the web page reloaded immediately, like as soon as response is sent, the web page is refresh, does someone know why please? The problem is surely because of the file upload because it only occur with the file being uploaded to the server.
import express from 'express';
import path from 'path';
import { fileURLToPath } from 'url';
import multer from 'multer';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const profileRouter = express.Router();
const upload = multer({dest:'./SPA/Back-end/uploads/images'});

function logger(req,res,next) {
console.log(`The request path is ${req.path} and the request method is ${req.method}`);
next();
}

profileRouter.use(logger);

profileRouter.post('/image', upload.single('profilePic'), (req,res) => {
console.log(req.body, req.file);
res.status(200).json({ message: 'File uploaded successfully!' }); // Respond with JSON
});

export {profileRouter}
import express from 'express';
import path from 'path';
import { fileURLToPath } from 'url';
import multer from 'multer';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const profileRouter = express.Router();
const upload = multer({dest:'./SPA/Back-end/uploads/images'});

function logger(req,res,next) {
console.log(`The request path is ${req.path} and the request method is ${req.method}`);
next();
}

profileRouter.use(logger);

profileRouter.post('/image', upload.single('profilePic'), (req,res) => {
console.log(req.body, req.file);
res.status(200).json({ message: 'File uploaded successfully!' }); // Respond with JSON
});

export {profileRouter}
55 replies
KPCKevin Powell - Community
Created by Faker on 11/25/2024 in #front-end
What is the purpose of blobs in JavaScript ?
Hello guys, I recently ran across the term "blob" in javaScript. I know it stands for 'Binary large objects' but concretely, what does it mean, why is it useful? Every files are stored as blobs? why? What is its usage?
16 replies
KPCKevin Powell - Community
Created by Faker on 11/24/2024 in #front-end
What is the purpose of the instance of FormData?
Hello guys, sorry to disturb you all; I have just learnt about FormData. I know it is mostly used for file uploads. But I don't understand how does it work, like sometimes peiple use an instance of FormData like formData to append something. For e.g: formData.append('name', value) I don't understand when do we use this formData.append ? Sometimes the form element reference is passed directly into the FormData constructor and we no longer need it... I'm a bit confuse of how it work, what if we need to upload multiple files for e.g.
13 replies
KPCKevin Powell - Community
Created by Faker on 11/24/2024 in #back-end
How to send file uploaded back to web app, like uploading a profile picture
Hello guys, I need to upload a picture on a website, like uploading a profile picture. What I first did is to send the image to an upload folder in my local server. Then how should I proceed to actually load and save that image on the website please
3 replies
KPCKevin Powell - Community
Created by Faker on 11/23/2024 in #front-end
Why don't we need to reset variables outside media queries
Hello guys, sorry to disturb you all.
:root {
--bg-color: rebeccapurple;
}
@media screen and (min-width: 600px) {
:root {
--bg-color: orangered;
}
}
:root {
--bg-color: rebeccapurple;
}
@media screen and (min-width: 600px) {
:root {
--bg-color: orangered;
}
}
I don't understand, we only define the background color for the variable only once. If it happens the background color changes due to our media query, if the screen size decreases back, will we get our default background color ? Because the css sheet isn't reloaded and we didn't set the background color back to its initial color.
17 replies
KPCKevin Powell - Community
Created by Faker on 11/22/2024 in #front-end
Review on login form and problems
No description
38 replies
KPCKevin Powell - Community
Created by Faker on 11/21/2024 in #front-end
Is event object and window.event object the same ?
Hello guys, sorry to disturb you, can someone explain what is the difference between an event object passed by an event handler and an a window event please. I just read that the window.event was used for backward compatibility like this: event = event || window.event I don't understand, event and window.event aren't the same thing ? for e,g consider the following:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Event vs window.event</title>
</head>
<body>
<button id="clickMe">Click Me</button>
<input id="typeHere" placeholder="Type something here" />
<script>
// Click Event Listener
document.getElementById("clickMe").addEventListener("click", (event) => {
console.log("---- Click Event ----");
console.log("event (local):", event);
console.log("window.event (global):", window.event);
});

// Input Event Listener
document.getElementById("typeHere").addEventListener("input", (event) => {
console.log("---- Input Event ----");
console.log("event (local):", event);
console.log("window.event (global):", window.event);
});
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Event vs window.event</title>
</head>
<body>
<button id="clickMe">Click Me</button>
<input id="typeHere" placeholder="Type something here" />
<script>
// Click Event Listener
document.getElementById("clickMe").addEventListener("click", (event) => {
console.log("---- Click Event ----");
console.log("event (local):", event);
console.log("window.event (global):", window.event);
});

// Input Event Listener
document.getElementById("typeHere").addEventListener("input", (event) => {
console.log("---- Input Event ----");
console.log("event (local):", event);
console.log("window.event (global):", window.event);
});
</script>
</body>
</html>
I didn't really understand what is the difference
8 replies