Bhai kya Banda haii master haii computer field ka nodejs pe kya command hai iski , wahhhh isee to Google, microsoft aasani se job mil sakti haii ... Great bro keep going ❤💯🔥
For people who are having issue with nanoid package, uninstall the existing nanoid package and install an older version, just run the following commands: npm uninstall nanoid npm install nanoid@3 This is will install the nanoid package which is compatible with CommonJS (which doesn't require you to change any code), the newer version only works with EJS modules
Few questions: 1. 06:08 Why you used express.Router() instead of express() 2. 12:26 How does this script start working and what is nodemon 3. 11:58 What did you do here, what is this localhost port, and how are you saving the data.
13:08 their was an error with nanoId : you can install this specific version of nanoId to remove this error : npm install nanoid@2.1.11 thanks me later😀
bhai I follow your same code and when i start npm the npm is running also but when i run send url from post man it always saying url is required please helpm me out
12:50 nanoid is throwing some error, which can be fixed by dunamically importing it - async function generateNewShortURL(req, res) { const body = req.body; if (!body.url) { return res.status(400).json({ error: "URL is required." }); } const { nanoid } = await import('nanoid'); const shortID = nanoid(8); // Generate the short ID await URL.create({ shortId: shortID, redirectURL: body.url, visitHistory: [], }); return res.json({ id: shortID }); };
i tried using nanoid and shortid for once post request works but when i try to make second its giving duplicate error, it's not generating unique shortID and get request for /:shortID also does not work
facing that error what should i do res.redirect( redirectURL); ^ ReferenceError: redirectURL is not defined at D:\Web devlopment\Projects\URL_SHORTNER\index.js:32:20 at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
19:40 I have generated several IDs with different URLs, but whenever I send get requests to those IDs (with the localhost URL as the prefix), I get redirected to the URL which is associated to the first entry in the database every single time. What could be the cause of this problem?
res.redirect(entry.redirectUrl) //bro pass an object like {shortId:shortid} in findOneAndUpdate and if you want to pass only {shortId} then your shortId should have same name as in database because it means {shortId:shortId}
it was not working because nano id supports common js syntax only upto version 3 and we are using version 5 solution : 1) use module syntax instead 2) degrade to version 3
when i add 1st new entry it add without error but when i add 2nd url it show error mongoServerError: E11000 duplicate key error collection: urlShortner.urls index: shortID_1 dup key: { shortID: null }
I am getting this error when I use generated shortid url in search bar: res.redirect(entry.redirectURL); ^ TypeError: Cannot read properties of null (reading 'redirectURL')
So For This I will Give Solution which is const entry = await Url.findOneAndUpdate({ shortId, }, { $push: { visitHistory: { timestamp: Date.now(), } } }); res.redirect(entry.redirectURL); }) Error is if you are Give if there are nothing return by entry Because Your name "shortId" is same in Your Schema "shortId " so Your Code will Succesfully Worked
Bhaiya can you please make a video on tracking the IP of the client in the analytics. As I was reading about this feature, this seams to be tricky in the case of proxy or load balancers.
EROER: npm : The term 'npm' is not recognized as the name of a cmdlet, function, script file, or operable program. the above error is being thrown by teminal when i am trying to execute the npm start command, pls reply ASAP sir its urgent for me!
thanks for the tutorial. I am getting an error. while using findOneAndUpdate It returns null because of which redirect is not working. I tried your code also but it is not working
it is the problem of res.redirect , it needs a protocol like http or https otherwise it consider the redirect as a relative path - this will throw out an error Use this instead const url=entry.redirectURL.startsWith('') || entry.redirectURL.startsWith('') ? entry.redirectURL :`${entry.redirectURL}` ; res.redirect(url)
may I know what extension are you using / what command are you using for organizing the code , cause when I use shift+alt+f it don't organize the way yours does.
bhaiya I'm getting Error: read ECONNRESET on postman even after using express.json() middleware , with the same error msg in the console which you got , help me fix it?
Brother we can solve nanoId() issue by simply write: { type: "module", }, In package.json Note: Change your import from require to import and also export to simple exports Thanks me letter🥰
on npmjs the shortid you have used is unavailable and now I'm using short unique id but this showing error so pls resolve this and what can i do.........pls check it sir
Halat patli ho gyi Bhai yeh project banate banate ... Kahin khudse banana pad Jaye Bina dekhe fir pata nhi kya ho.... It seems quite difficult right now😮
@@deepeshkhatri5370 Hi short id and nano id both are not working so pleaes dont use them instead use this code:- function generateRandomString(n) { const str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; let randomString = ""; for(let i = 0 ; i < n ; i++) { const random = Math.floor(Math.random()*str.length); randomString += str[random]; } return randomString; } module.exports = generateRandomString; I think you guys might have already gotten the solution since its 10 months 😅
Hi Piyush, I am Vishal doing Practice with the help of this video. I got stuck whiten an error which I am pasting below. could you please help me out to fixed it. Thanks! C:\Users\Taruna\OneDrive\Desktop\SHORT-URL ode_modules\mongoose\lib\document.js:3306 this.$__.validationError = new ValidationError(this); ^ ValidationError: url validation failed: shortId: Path `shortId` is required.
I want to become a full-stack developer, and initially, I only knew React.js. Upon searching for Node.js tutorials, I came across your playlist of 48 videos. These videos are incredibly informative, and I had never learned Node.js before. After watching your tutorials, I've become a fan of your teaching style. Thank you so much for guiding us in such a great way!
Node ka real feel iss bnde me Diya h, hats off man❤
same brother same, literally same!
thoda complex laga sab ek sath, but it was unbelievable 23 mins k video me itna sab kuch.. Vid - 21✅
Bhai kya Banda haii master haii computer field ka nodejs pe kya command hai iski , wahhhh isee to Google, microsoft aasani se job mil sakti haii ...
Great bro keep going ❤💯🔥
For people who are having issue with nanoid package, uninstall the existing nanoid package and install an older version, just run the following commands:
npm uninstall nanoid
npm install nanoid@3
This is will install the nanoid package which is compatible with CommonJS (which doesn't require you to change any code), the newer version only works with EJS modules
wow , what a tutorial , I watch the entire video and its very fun to code along
Few questions:
1. 06:08 Why you used express.Router() instead of express()
2. 12:26 How does this script start working and what is nodemon
3. 11:58 What did you do here, what is this localhost port, and how are you saving the data.
Bro Just watch the tutorial from starting lec-1
bruh you don't even know the basics, I recommend watching from the start dude.
Yes bro watched the node js tutorial from starting these all the basics which you are asking here
tmkc
brother you are teach people or self study your tutorial is very fast.
13:08 their was an error with nanoId : you can install this specific version of nanoId to remove this error : npm install nanoid@2.1.11
thanks me later😀
❤❤❤❤
ShortID no longer Supported
its Amazing Project , After watching this video I understood how this type of website works in backend side
Project completed ✅
Maja agya error handle karne mein ❤
Bhai maza aagya. awesome approach 🥳
bhai Apka coding logic aur samjhane ka tareeka bht acha hai.. really loved it bhai🎀
Osem content Hindi language fabulous teaching method thanks sir
Thanks and welcome
@@piyushgargdev hello sir Abhi Tak youtube pe mern series nahi hai good content with project aap apne chenal pe layiye hindi me
i like the way you explain and also i learning how to read docs
Congrats For 100k MAn
love your playlist
I was getting error with both nanoid and shortid , so I used nanoid@^3.0.0
I am not understanding these fucking topics 😅 what to do bro I am not liking can u suggest what u are doing now
Is it working ?
thanks bud
ShortId and nano Id are not working for me. I used another library caller short-unique-id
@@adityabisoyi1502 die with errors and dsa systemdesign and webdev
Fantastic course. Node js ka feel aa gaya
bhai tune, short url project banye hai..?
You make really fantastic videos. I like the way of your teaching and writing the code in efficient manner. wow It's really outstanding...
URL Shortner created Done✅ thanks sir jee
have you completed url shortner ..?is shortid package was working..?
can u please share the source code my nanoid package is not working
Bro you deserve 👏 great learning
bhai I follow your same code and when i start npm the npm is running also but when i run send url from post man it always saying url is required please helpm me out
please keep up the classes free on youtube. They are so helpful.
thank you for your quality content
Does your nanoid works?
@@utsavscreativity13 no its not working, probably it's not supporting version 20
amazing and simple project for beginners like me✨✨
18:02 bhai ye entry par hover karne suggestions kaise aaya?
Koi extension ho to batao!!
best series ever
I like the way you explain
12:50 nanoid is throwing some error, which can be fixed by dunamically importing it -
async function generateNewShortURL(req, res) {
const body = req.body;
if (!body.url) {
return res.status(400).json({
error: "URL is required."
});
}
const { nanoid } = await import('nanoid');
const shortID = nanoid(8); // Generate the short ID
await URL.create({
shortId: shortID,
redirectURL: body.url,
visitHistory: [],
});
return res.json({ id: shortID });
};
bhai post request mee short url response aa raha hai lekin get request me kare toh error 404 aa raha hai...
bhai thanks yaar. koi shittalks kare bina itna accha samjhata h na bhai, ki samajhne m bhi maja ata h
Excellent explanation❤
19:37 if you send this local host url to your friend do you think it will work?
thanks bro for the great video
Nice video bhaiya
nice explanation thanks for great video!!
Interesting video, nice explanation Thanks
Thank you so much sir
Thanks🧡, nice video
if getting this error ->
res.redirect(entry.redirectedURL);
^
TypeError: Cannot read properties of null (reading 'redirectedURL')
at D:
ode js\URL-Shortner\index.js:27:22
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Node.js v18.16.0
[nodemon] app crashed - waiting for file changes before starting...
solution -
res.redirect('' + entry.redirectURL);
thankss can u tell me how you got this solution?
Same Here If You Have Any Solution Than tell me ...
Did u got the solution?
Thank You Brother!!
yeah i also got this error can , solution mila ki nahi bhai
Bhai ksm se aapka playlist mila ... n and tb se mere liye jode js aasan ho chuka hai
i tried using nanoid and shortid for once post request works but when i try to make second its giving duplicate error, it's not generating unique shortID and get request for /:shortID also does not work
const URL = require("../models/url");
async function handleGenerateNewShortURL(req, res) {
const { nanoid } = await import("nanoid");
const body = req.body;
if (!body.url) return res.status(400).json({ error: "url is required!" });
const shortID = nanoid(8);
await URL.create({
shortId: shortID,
redirectUrl: body.url,
visitHistory: [],
});
return res.json({ id: shortID });
}
module.exports = { handleGenerateNewShortURL };
Sir will you upload react native course please tell me?
facing that error what should i do
res.redirect( redirectURL);
^
ReferenceError: redirectURL is not defined
at D:\Web devlopment\Projects\URL_SHORTNER\index.js:32:20
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
same with me did u solved it ?
great video bhaiya what will be the next video?
Wait till 5:00PM 💪🏻
19:40 I have generated several IDs with different URLs, but whenever I send get requests to those IDs (with the localhost URL as the prefix), I get redirected to the URL which is associated to the first entry in the database every single time. What could be the cause of this problem?
const shortid = req.params.shortId;
const entry = await URL.findOneAndUpdate({shortId:shortid},{
$push:{visitHistory:{timestamp:Date.now()}}
})
res.redirect(entry.redirectUrl)
//bro pass an object like {shortId:shortid} in findOneAndUpdate and if you want to pass only {shortId} then your shortId should have same name as in database because it means {shortId:shortId}
same problem , did you find any error regarding this
I am not getting the desired output for the last part ...for number of clicks....the postman is showing cannot get ......please help!!
What error are you facing?
I am also facing the same
@@AdityaSingh-yz9g it works fine in website
not with me I am not getting the website when I get request from postman
it was not working because nano id supports common js syntax only upto version 3 and we are using version 5
solution : 1) use module syntax instead
2) degrade to version 3
getting error on postman get request "Cannot GET /url/8iN0AH5hG" also used yr source code but still getting issue how to fix can u help ?
router.get("/analytics/:shortId",handleAnyalytics) try this path
same issue , have you found the solution???
when i add 1st new entry it add without error but when i add 2nd url it show error
mongoServerError: E11000 duplicate key error collection: urlShortner.urls index: shortID_1 dup key: { shortID: null }
facing same problem bro is you got any solution please share kar dena
it seems to be a problem where you are overwriting, are you sure you are creating new field instead of updating?
same error , did you resolve it ?
same error did you resolve
@@SUBZERO-vx7xs yeah i had to drop the database
I am getting this error when I use generated shortid url in search bar:
res.redirect(entry.redirectURL);
^
TypeError: Cannot read properties of null (reading 'redirectURL')
This might solve the issue: (entry?.redirectURl)
Your two routes are clashing.
@@niteshkushwaha9493 then how to solve this ?
could be an unresolved promise, are you sure you are using async await or .then right?
So For This I will Give Solution which is
const entry = await Url.findOneAndUpdate({
shortId,
}, {
$push: {
visitHistory: {
timestamp: Date.now(),
}
}
});
res.redirect(entry.redirectURL);
})
Error is if you are Give if there are nothing return by entry Because Your name "shortId" is same in Your Schema "shortId " so Your Code will Succesfully Worked
Now my only goal is to be perfectionist like him while my hands on keyboard. ....how much does it take to be pro in backend?
Bhaiya can you please make a video on tracking the IP of the client in the analytics. As I was reading about this feature, this seams to be tricky in the case of proxy or load balancers.
how to enable suggestions like jo mongo k aa rahe hai findOneByUpdate bro?
EROER: npm : The term 'npm' is not recognized as the name of a cmdlet, function, script file, or operable program.
the above error is being thrown by teminal when i am trying to execute the npm start command, pls reply ASAP sir its urgent for me!
thanks for the tutorial. I am getting an error. while using findOneAndUpdate It returns null because of which redirect is not working. I tried your code also but it is not working
I am also getting the same error
check if u have exported and imported database properly
@@comparisondata2473 yes imported correctly.
it is the problem of res.redirect , it needs a protocol like http or https otherwise it consider the redirect as a relative path - this will throw out an error
Use this instead
const url=entry.redirectURL.startsWith('') || entry.redirectURL.startsWith('') ? entry.redirectURL :`${entry.redirectURL}` ;
res.redirect(url)
await is not working for res.redirect
can you please help
use async function then you will be able to use await
14:18 terminal clear krke prompt top pr kaise kiya ? koi shortcut key hai qa
CMD K for Mac and CTRL + K for windows
Route.post() requires a callback function but got a [object Undefined]
if(!body.url){ return res.json({error:"URL Needed"}) }
^
TypeError: Cannot read properties of undefined (reading 'url')
Any one ??
Included app.use(express.json()) middleware in the index.js?
and make sure that you add on the top of url roure
sir postman not connect error 404 but code is same please provde same code
shortid has been reprecated, any other package recommended?
ssid
may I know what extension are you using / what command are you using for organizing the code , cause when I use shift+alt+f it don't organize the way yours does.
he is using Prettier extension
I use that too , though It feels like his does a lot better
LOL
thats the beauty of MacOS @@parasagarwal5701
@@parasagarwal5701 if you select the code and then formatting with prettier then it should work fine
Hi there, I am a little bit confused, won't this URL shortner only work on the machine in which npm is running
Deployment ke bad sab machine pe work krega.
bhaiya I'm getting Error: read ECONNRESET on postman even after using express.json() middleware , with the same error msg in the console which you got , help me fix it?
has the error been resolved? i am stuck too.
Brother we can solve nanoId() issue by simply write:
{
type: "module",
}, In package.json
Note: Change your import from require to import and also export to simple exports
Thanks me letter🥰
where did you declare urlRoute before importing
Video useful
on npmjs the shortid you have used is unavailable and now I'm using short unique id but this showing error so pls resolve this and what can i do.........pls check it sir
same
SyntaxError: Unexpected end of JSON input
at JSON.parse () ye error ara hai mera
Halat patli ho gyi Bhai yeh project banate banate ...
Kahin khudse banana pad Jaye Bina dekhe fir pata nhi kya ho....
It seems quite difficult right now😮
Same here.. is playlist ki Kitne videos dekh lie aapne abhi tak?
can i explain for me, when i run my code, i have a problem that shortid not a function?
pls pls
issue resolved?
@@rishitsingh7195 this issue hasn's been resolved yet:(((
can you help me pls
@@QuốcĐặng-e7p I too need the solution bro
@@rishitsingh7195 issue resolved, you need import trueway
Bhaiya bahut error aa raha hai kuch samajh nahi aa raha hai ki kya kare jabki code same to same likh rahe hai
Bhai Sikh rhe ho node js ?
Ja chod dia ..
Bcoz Maine abhi start Kia hai koi tips le lu
I understood the code, but I didn't understand the purpose of this app
I mean why do we need short url anyways?
kahi kahi pe bahut badi url hoti hai that's why, and hui baat linkedin ki to linkedin pe limit hai url ki to ye waha pe bhi kaam aa sakta hai
how handlegenerateshorturl function get req and res objects?
ValidationError: url validation failed: redirecturl: Path `redirecturl` is required.
Thanks bro
pls give some basic knowledge on mongodb also ...i feel its going fast in between
@piyush bhaiya source code link is not working
mila link ya koi hint ?
mere wale me problem aa rahi hai
@ nhi mila koi link bhai
I love it
Great Content
Hey can anyone help me... I'm getting a... TypeError: Cannot read properties of undefined (reading 'push')
bro replace Router to Router();
I am getting confused because mongodb is not running properly in my project
excellent
Sir your source code link is not working
mila link ya koi hint ?
mere wale me problem aa rahi hai
I want to ask how this short id work??
what is small letters url in schema here?
Nice
i got this error ..ValidationError: url validation failed: shortID: Path `shortID` is required.
me too
,any solutions
@@deepeshkhatri5370 Hi short id and nano id both are not working so pleaes dont use them instead use this code:-
function generateRandomString(n) {
const str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
let randomString = "";
for(let i = 0 ; i < n ; i++) {
const random = Math.floor(Math.random()*str.length);
randomString += str[random];
}
return randomString;
}
module.exports = generateRandomString;
I think you guys might have already gotten the solution since its 10 months
😅
Hi Piyush, I am Vishal doing Practice with the help of this video. I got stuck whiten an error which I am pasting below. could you please help me out to fixed it. Thanks!
C:\Users\Taruna\OneDrive\Desktop\SHORT-URL
ode_modules\mongoose\lib\document.js:3306
this.$__.validationError = new ValidationError(this);
^
ValidationError: url validation failed: shortId: Path `shortId` is required.
so na tumne Schema ke under shortid ko required true kiya hoga na that's right uske wajah se kuch lag rha hai
Download Source Code is not working...
console.log("tut was grea, but file naming confused me a lot");
Sir your react and next JS course is completed or not?
Next is completed, After Nodejs, we are going to cover React from scratch and in - depth
I want to become a full-stack developer, and initially, I only knew React.js. Upon searching for Node.js tutorials, I came across your playlist of 48 videos. These videos are incredibly informative, and I had never learned Node.js before. After watching your tutorials, I've become a fan of your teaching style. Thank you so much for guiding us in such a great way!
How to deploy this on server ?
make a video on mongodb module in Nodejs
Where is the second video
TypeError: Cannot read properties of null (reading 'redirectURL') , Anyone please help how to resolve it.
Exactly, I m also getting the same error..
@@satyamraj2779 Yep same error
try res.redirect('' + entry.redirectURL);
add while passing the URL. Hope it helps
I am getting this error"url validation failed: shortid: Path `shortid` is required."
how to resolve this
same any solution?
I am getting error that database not connected
bhaiya can you please provide code for this video.
anyone following along, I'm getting entry as null and so redirect is not working, pls help
though every time I'm hitting get method visitHistory is updating