Create a Custom URL Shortener using Node.JS and MongoDB

  Рет қаралды 79,287

Piyush Garg

Piyush Garg

Жыл бұрын

► Master NodeJS Playlist: • Master NodeJS
► Download Source Code: www.piyushgarg.dev/files/code...
Learn how to build your own URL shortener service using Node.js, Express, and MongoDB. In this video tutorial, we'll show you step-by-step how to set up the server, connect to a MongoDB database, and implement the functionality to shorten and redirect URLs. Perfect for beginners and experienced developers alike!
► Complete Full Stack Web Developer RoadMap 2023: • Complete Full Stack We...
Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine. It allows developers to run JavaScript on the server side, creating server-side applications with JavaScript.
► My Website: www.piyushgarg.dev
My Gears
► My Girlfriend: amzn.to/3WD6FRp
► Apple MacBook Laptop: amzn.to/3WBJgQn
► Anker USB Hub: amzn.to/3GhZSr0
► Blue Yeti Microphone: amzn.to/3YKZ9FT
► External 27” Monitor: amzn.to/3Vp3xaO
► Logitech MK295 Wireless Keyboard and Mouse: amzn.to/3DuL1bB
► Seagate Expansion 1TB External HDD: amzn.to/3QMm5Q8
► Tripod: amzn.to/3S4OwK4
► Ring Light: amzn.to/3YLf8DR
Disclaimer: All the links above are affiliate links.
Social Links
► Twitter - / piyushgarg_dev
► LinkedIn - / piyushgarg195
Video Titles
Create Your Own URL Shortener Service with Node.js, Express, and MongoDB
Make a URL Shortener App in Node.js and Express - Beginner's Guide
Making a URL Shortening Application using Node.js, Express and MongoDB
Tags
#nodejs #javascript #expressjs #mongodb #mernstack #developer #api #https #server #javascriptinhindi #webdevelopment #webapp #realtimeapp #serverside #nonblockingio #tech

Пікірлер: 219
@recap9117
@recap9117 6 ай бұрын
Node ka real feel iss bnde me Diya h, hats off man❤
@BestURLShortenerBioPageQRCode
@BestURLShortenerBioPageQRCode 9 ай бұрын
Thank you for your great efforts! Really really awesome video.
@Crazy_philosopher
@Crazy_philosopher Ай бұрын
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 ❤💯🔥
@user-hn2xg5no9r
@user-hn2xg5no9r 7 ай бұрын
You make really fantastic videos. I like the way of your teaching and writing the code in efficient manner. wow It's really outstanding...
@AbhinavSingh-bp5qh
@AbhinavSingh-bp5qh Жыл бұрын
love your playlist
@user-rl3ln2ih1m
@user-rl3ln2ih1m Жыл бұрын
nice explanation thanks for great video!!
@69pinkman50
@69pinkman50 3 ай бұрын
Congrats For 100k MAn
@prasadmutnale773
@prasadmutnale773 6 ай бұрын
i like the way you explain and also i learning how to read docs
@satyampal7235
@satyampal7235 4 ай бұрын
Bhai maza aagya. awesome approach 🥳
@RohitKumar-dy2gc
@RohitKumar-dy2gc 4 ай бұрын
amazing and simple project for beginners like me✨✨
@user-mh4sp2im1k
@user-mh4sp2im1k 8 ай бұрын
Interesting video, nice explanation Thanks
@Sandy-ip2mm
@Sandy-ip2mm 2 ай бұрын
thanks bro for the great video
@poojaganvir5631
@poojaganvir5631 5 ай бұрын
Thanks🧡, nice video
@bunnytheweebster
@bunnytheweebster 6 ай бұрын
thoda complex laga sab ek sath, but it was unbelievable 23 mins k video me itna sab kuch.. Vid - 21✅
@Vivek-rn9zb
@Vivek-rn9zb Жыл бұрын
Nice video bhaiya
@apoorvaraj3894
@apoorvaraj3894 2 ай бұрын
Excellent explanation❤
@aesthetic_universe
@aesthetic_universe 26 күн бұрын
if getting this error -> res.redirect(entry.redirectedURL); ^ TypeError: Cannot read properties of null (reading 'redirectedURL') at D: ode js\URL-Shortner\index.js:<a href="#" class="seekto" data-time="1642">27:22</a> at process.processTicksAndRejections (node:internal/process/task_queues:9<a href="#" class="seekto" data-time="305">5:5</a>) Node.js v18.16.0 [nodemon] app crashed - waiting for file changes before starting... solution - res.redirect('' + entry.redirectURL);
@ramanandkrgupta
@ramanandkrgupta 7 күн бұрын
Thanks man
@vineetkumar2899
@vineetkumar2899 Жыл бұрын
I love it
@SulavGhimireeee
@SulavGhimireeee 6 ай бұрын
Thanks bro
@harshpandey7970
@harshpandey7970 18 күн бұрын
Fantastic course. Node js ka feel aa gaya
@kishankg7056
@kishankg7056 3 күн бұрын
bhai tune, short url project banye hai..?
@shivanshusingh7660
@shivanshusingh7660 8 ай бұрын
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
@shubhamgupta-bl1tr
@shubhamgupta-bl1tr Жыл бұрын
Nice
@Avaneesh..
@Avaneesh.. Ай бұрын
excellent
@aakashsikligar7738
@aakashsikligar7738 6 ай бұрын
Really great video sir! just a suggestion if we install previous version on nanoid - nanoid@3 then we don't get an error
@user-su7eh6yr7k
@user-su7eh6yr7k 5 ай бұрын
URL Shortner created Done✅ thanks sir jee
@kishankg7056
@kishankg7056 3 күн бұрын
have you completed url shortner ..?is shortid package was working..?
@saptarshisinha1744
@saptarshisinha1744 3 ай бұрын
Project completed ✅ Maja agya error handle karne mein ❤
@saranyasingh6847
@saranyasingh6847 Жыл бұрын
I was getting error with both nanoid and shortid , so I used nanoid@^3.0.0
@abc-ym4zs
@abc-ym4zs 8 ай бұрын
I am not understanding these fucking topics 😅 what to do bro I am not liking can u suggest what u are doing now
@user-cj7ec4tm2f
@user-cj7ec4tm2f 7 ай бұрын
Is it working ?
@bunnytheweebster
@bunnytheweebster 6 ай бұрын
thanks bud
@adityabisoyi1502
@adityabisoyi1502 5 ай бұрын
ShortId and nano Id are not working for me. I used another library caller short-unique-id
@abc-ym4zs
@abc-ym4zs 5 ай бұрын
@@adityabisoyi1502 die with errors and dsa systemdesign and webdev
@VikasSharma-kc2oc
@VikasSharma-kc2oc Жыл бұрын
🔥🔥
@SaurabhKumar-qc6og
@SaurabhKumar-qc6og 6 ай бұрын
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.
@codewithhindi
@codewithhindi Жыл бұрын
Osem content Hindi language fabulous teaching method thanks sir
@piyushgargdev
@piyushgargdev Жыл бұрын
Thanks and welcome
@codewithhindi
@codewithhindi Жыл бұрын
@@piyushgargdev hello sir Abhi Tak youtube pe mern series nahi hai good content with project aap apne chenal pe layiye hindi me
@shaktilab
@shaktilab 11 ай бұрын
how handlegenerateshorturl function get req and res objects?
@lovelymusic3549
@lovelymusic3549 Жыл бұрын
Sir will you upload react native course please tell me?
@The_Builder_Bobs
@The_Builder_Bobs 3 ай бұрын
where did you declare urlRoute before importing
@mma-dost
@mma-dost Жыл бұрын
great video bhaiya what will be the next video?
@piyushgargdev
@piyushgargdev Жыл бұрын
Wait till 5:00PM 💪🏻
@user-bo8ls6uc3c
@user-bo8ls6uc3c 17 күн бұрын
shortid has been reprecated, any other package recommended?
@AbhiGamingYT0234
@AbhiGamingYT0234 3 сағат бұрын
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!
@prasiddhbarot9323
@prasiddhbarot9323 Жыл бұрын
<a href="#" class="seekto" data-time="1082">18:02</a> bhai ye entry par hover karne suggestions kaise aaya? Koi extension ho to batao!!
@ayushshrey9916
@ayushshrey9916 Жыл бұрын
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')
@aniket5657
@aniket5657 10 ай бұрын
This might solve the issue: (entry?.redirectURl)
@niteshkushwaha9493
@niteshkushwaha9493 9 ай бұрын
Your two routes are clashing.
@cws20128
@cws20128 7 ай бұрын
@@niteshkushwaha9493 then how to solve this ?
@UzairKhan-qd3xu
@UzairKhan-qd3xu 5 ай бұрын
could be an unresolved promise, are you sure you are using async await or .then right?
@KirtanPatel552
@KirtanPatel552 5 ай бұрын
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
@user-qv5jt1sq9n
@user-qv5jt1sq9n 11 ай бұрын
I am getting confused because mongodb is not running properly in my project
@SimpleProgrammer0
@SimpleProgrammer0 5 ай бұрын
<a href="#" class="seekto" data-time="788">13:08</a> 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😀
@parasagarwal5701
@parasagarwal5701 5 ай бұрын
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.
@navneetsinha8387
@navneetsinha8387 4 ай бұрын
he is using Prettier extension
@parasagarwal5701
@parasagarwal5701 4 ай бұрын
I use that too , though It feels like his does a lot better LOL
@devilsworld7299
@devilsworld7299 4 ай бұрын
thats the beauty of MacOS @@parasagarwal5701
@rajeshhalder2774
@rajeshhalder2774 4 ай бұрын
@@parasagarwal5701 if you select the code and then formatting with prettier then it should work fine
@adityaS011
@adityaS011 11 ай бұрын
Where is the second video
@pranavsingh2238
@pranavsingh2238 Жыл бұрын
Hi there, I am a little bit confused, won't this URL shortner only work on the machine in which npm is running
@chetanram797
@chetanram797 11 ай бұрын
Deployment ke bad sab machine pe work krega.
@dev_opsenginner4383
@dev_opsenginner4383 9 ай бұрын
make a video on mongodb module in Nodejs
@vishalsaini1180
@vishalsaini1180 3 ай бұрын
facing that error what should i do res.redirect( redirectURL); ^ ReferenceError: redirectURL is not defined at D:\Web devlopment\Projects\URL_SHORTNER\index.js:<a href="#" class="seekto" data-time="1940">32:20</a> at process.processTicksAndRejections (node:internal/process/task_queues:9<a href="#" class="seekto" data-time="305">5:5</a>)
@mrxpandaplays2185
@mrxpandaplays2185 22 күн бұрын
same with me did u solved it ?
@roshannayak5982
@roshannayak5982 10 ай бұрын
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 ?
@omkarjagtap2212
@omkarjagtap2212 6 ай бұрын
router.get("/analytics/:shortId",handleAnyalytics) try this path
@decodewithd2541
@decodewithd2541 2 ай бұрын
same issue , have you found the solution???
@vageshnp6792
@vageshnp6792 4 ай бұрын
I am getting error that database not connected
@Sameer-codes
@Sameer-codes 11 ай бұрын
await is not working for res.redirect can you please help
@anandshete9170
@anandshete9170 5 ай бұрын
use async function then you will be able to use await
@AtharvJoshi-jc7ow
@AtharvJoshi-jc7ow 20 күн бұрын
I understood the code, but I didn't understand the purpose of this app I mean why do we need short url anyways?
@awanishmishra4611
@awanishmishra4611 Ай бұрын
How to deploy this on server ?
@shubhamchauhan6633
@shubhamchauhan6633 Жыл бұрын
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
@iamksb
@iamksb Жыл бұрын
I am also getting the same error
@comparisondata2473
@comparisondata2473 9 ай бұрын
check if u have exported and imported database properly
@nityaranjan6714
@nityaranjan6714 9 ай бұрын
@@comparisondata2473 yes imported correctly.
@priyajha3700
@priyajha3700 6 ай бұрын
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)
@sankalpnaik877
@sankalpnaik877 6 ай бұрын
I am not getting the desired output for the last part ...for number of clicks....the postman is showing cannot get ......please help!!
@animeshbiswas2754
@animeshbiswas2754 6 ай бұрын
What error are you facing?
@AdityaSingh-yz9g
@AdityaSingh-yz9g 6 ай бұрын
I am also facing the same
@sankalpnaik877
@sankalpnaik877 6 ай бұрын
@@AdityaSingh-yz9g it works fine in website
@AdityaSingh-yz9g
@AdityaSingh-yz9g 6 ай бұрын
not with me I am not getting the website when I get request from postman
@geeky_world
@geeky_world 5 ай бұрын
pls give some basic knowledge on mongodb also ...i feel its going fast in between
@sudhanshugorwadkar3839
@sudhanshugorwadkar3839 10 ай бұрын
<a href="#" class="seekto" data-time="1180">19:40</a> 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?
@Ankit-01-01
@Ankit-01-01 9 ай бұрын
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}
@SUBZERO-vx7xs
@SUBZERO-vx7xs 3 ай бұрын
same problem , did you find any error regarding this
@himanshutiwari3442
@himanshutiwari3442 Ай бұрын
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
@udy1897
@udy1897 25 күн бұрын
same
@peatear9421
@peatear9421 Ай бұрын
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?
@AmitMusic-02
@AmitMusic-02 23 күн бұрын
has the error been resolved? i am stuck too.
@user-hx4er4pe8b
@user-hx4er4pe8b 3 ай бұрын
if(!body.url){ return res.json({error:"URL Needed"}) } ^ TypeError: Cannot read properties of undefined (reading 'url') Any one ??
@user-gm7xg5nc4g
@user-gm7xg5nc4g 2 ай бұрын
Included app.use(express.json()) middleware in the index.js?
@AjayKumar-bj4hk
@AjayKumar-bj4hk 9 күн бұрын
and make sure that you add on the top of url roure
@moviesasylum8531
@moviesasylum8531 2 ай бұрын
how to connect it to online mongoDB
@AjayKumar-bj4hk
@AjayKumar-bj4hk 9 күн бұрын
ValidationError: url validation failed: redirecturl: Path `redirecturl` is required.
@madmax180
@madmax180 5 ай бұрын
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
@abhishekgaikwad3977
@abhishekgaikwad3977 6 ай бұрын
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 }
@tanishkgupta6149
@tanishkgupta6149 5 ай бұрын
facing same problem bro is you got any solution please share kar dena
@UzairKhan-qd3xu
@UzairKhan-qd3xu 5 ай бұрын
it seems to be a problem where you are overwriting, are you sure you are creating new field instead of updating?
@SUBZERO-vx7xs
@SUBZERO-vx7xs 3 ай бұрын
same error , did you resolve it ?
@solaimfaisal
@solaimfaisal Ай бұрын
same error did you resolve
@solaimfaisal
@solaimfaisal Ай бұрын
@@SUBZERO-vx7xs yeah i had to drop the database
@satyamjha-codeindwala6666
@satyamjha-codeindwala6666 4 ай бұрын
Node.JS and MongoDB
@DesertCentipede
@DesertCentipede 12 күн бұрын
console.log("tut was grea, but file naming confused me a lot");
@Hrishabhhhh
@Hrishabhhhh Ай бұрын
Hey can anyone help me... I'm getting a... TypeError: Cannot read properties of undefined (reading 'push')
@studyplans3783
@studyplans3783 Ай бұрын
bro replace Router to Router();
@nikitabhardwaj1876
@nikitabhardwaj1876 6 күн бұрын
everytime i run this it shows this [nodemon] app crashed - waiting for file changes before starting...
@sauravmishra2732
@sauravmishra2732 6 күн бұрын
i am also getting same as URL.create is not a function
@warrior_pk
@warrior_pk Жыл бұрын
<a href="#" class="seekto" data-time="858">14:18</a> terminal clear krke prompt top pr kaise kiya ? koi shortcut key hai qa
@piyushgargdev
@piyushgargdev Жыл бұрын
CMD K for Mac and CTRL + K for windows
@vishnugupta6284
@vishnugupta6284 16 күн бұрын
Great Content
@shashankchaudhary3625
@shashankchaudhary3625 11 ай бұрын
i got this error ..ValidationError: url validation failed: shortID: Path `shortID` is required.
@deepeshkhatri5370
@deepeshkhatri5370 6 ай бұрын
me too ,any solutions
@aliasgeranees8893
@aliasgeranees8893 Ай бұрын
@@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 😅
@bhaisaheb4686
@bhaisaheb4686 2 ай бұрын
anyone following along, I'm getting entry as null and so redirect is not working, pls help
@bhaisaheb4686
@bhaisaheb4686 2 ай бұрын
though every time I'm hitting get method visitHistory is updating
@Vivek-rn9zb
@Vivek-rn9zb Жыл бұрын
Bhaiya bahut error aa raha hai kuch samajh nahi aa raha hai ki kya kare jabki code same to same likh rahe hai
@mandeepsingh2718
@mandeepsingh2718 4 ай бұрын
Bhai Sikh rhe ho node js ? Ja chod dia .. Bcoz Maine abhi start Kia hai koi tips le lu
@technicalabhi7683
@technicalabhi7683 Жыл бұрын
Make video on get ip address
@harshitjoshi3082
@harshitjoshi3082 Жыл бұрын
Just console.log req.ip ?
@decodewithd2541
@decodewithd2541 2 ай бұрын
I am getting error while sending the GET request , help me
@velanthevar2459
@velanthevar2459 2 ай бұрын
In the router folder post request is made so you should send the post request
@nityaranjan6714
@nityaranjan6714 9 ай бұрын
TypeError: Cannot read properties of null (reading 'redirectURL') , Anyone please help how to resolve it.
@satyamraj2779
@satyamraj2779 8 ай бұрын
Exactly, I m also getting the same error..
@cws20128
@cws20128 7 ай бұрын
@@satyamraj2779 Yep same error
@pragatiailani7206
@pragatiailani7206 7 ай бұрын
try res.redirect('' + entry.redirectURL);
@ankurshukla7889
@ankurshukla7889 6 ай бұрын
add while passing the URL. Hope it helps
@lovelymusic3549
@lovelymusic3549 Жыл бұрын
Sir your react and next JS course is completed or not?
@piyushgargdev
@piyushgargdev Жыл бұрын
Next is completed, After Nodejs, we are going to cover React from scratch and in - depth
@shashisahani800
@shashisahani800 5 ай бұрын
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!
@shi-nee7966
@shi-nee7966 Жыл бұрын
why did we made history as array of objects?
@hemangkoshiyar
@hemangkoshiyar 4 ай бұрын
because he wanted to store multiple timestamps to determine the length of url hits and array is used to store multiple entries.
@user-cx3md3rz8h
@user-cx3md3rz8h 5 ай бұрын
sir postman not connect error 404 but code is same please provde same code
@whyDude123
@whyDude123 2 ай бұрын
Check the description of this video
@awdheshprasad9685
@awdheshprasad9685 Жыл бұрын
I am getting this error"url validation failed: shortid: Path `shortid` is required." how to resolve this
@shashankchaudhary3625
@shashankchaudhary3625 11 ай бұрын
same any solution?
@shashankchaudhary3625
@shashankchaudhary3625 11 ай бұрын
i was getting error url validation failed
@bineetjha2268
@bineetjha2268 4 ай бұрын
same mee too getting this error
@sushantlama2178
@sushantlama2178 Жыл бұрын
bhai Im getting error while I'm using get with the shortId help please
@piyushgargdev
@piyushgargdev Жыл бұрын
Kya error aaya?
@sushantlama2178
@sushantlama2178 Жыл бұрын
@@piyushgargdev Jaab mey generate short id leke get request karna chahata huu tab error atta hey paar terminal pey kuch bhi nahi error dekhata hey..sirf postman pey request error atta hey jaab mey get karna chahata huu
@roshannayak5982
@roshannayak5982 10 ай бұрын
same issue how to u find ans ? @@sushantlama2178
@sankalpnaik877
@sankalpnaik877 6 ай бұрын
Hua kya solve?
@decodewithd2541
@decodewithd2541 2 ай бұрын
@@sushantlama2178 same issue , resolve hua if yes please help me
@ramkrushnaprabhu8027
@ramkrushnaprabhu8027 Жыл бұрын
Sir, How to collect ip address? Please reply...
@priyanshuhaldar472
@priyanshuhaldar472 3 ай бұрын
You get it in the req object itself. You can use that trick to create a rate limiter.
@mandeepsingh2718
@mandeepsingh2718 4 ай бұрын
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😮
@gamerschoice779
@gamerschoice779 2 ай бұрын
Same here.. is playlist ki Kitne videos dekh lie aapne abhi tak?
@Vivek-rn9zb
@Vivek-rn9zb Жыл бұрын
Bhaiya yah project jaldi complete kar dijiyega please bhaiya
@piyushgargdev
@piyushgargdev Жыл бұрын
Hanji Zarur
@charanmane4178
@charanmane4178 Ай бұрын
<a href="#" class="seekto" data-time="528">8:48</a>
@yashigupta2212
@yashigupta2212 9 ай бұрын
Code is not working
@user-mt5xc6de6l
@user-mt5xc6de6l Жыл бұрын
The code gives: res.redirect(entry.redirectURL); ^ TypeError: Cannot read properties of null (reading 'redirectURL') in latest mongoDB version . How do I fix this?
@pranavsingh2238
@pranavsingh2238 Жыл бұрын
that particular portion must be app.get('/:shortId', async (req,res) => { const shortId = req.params.shortId; const entry = await URL.findOneAndUpdate({ //this part wouldn't be present for sure shortId }, { $push: { visitHistory:{ timestamp: Date.now(),}, }, } ); res.redirect(entry.redirectURL); });
@mistake10449
@mistake10449 10 ай бұрын
what's the solution ? @@pranavsingh2238
@nityaranjan6714
@nityaranjan6714 9 ай бұрын
Same error I am also getting. And with below solution its not working.
@nityaranjan6714
@nityaranjan6714 9 ай бұрын
@@pranavsingh2238 Sorry I could not able to understand your solution. Could you please explain what should I do?
@pragatiailani7206
@pragatiailani7206 7 ай бұрын
try res.redirect('' + entry.redirectURL);
@sankhasuvraghatak
@sankhasuvraghatak 4 ай бұрын
const err = new MongooseError(message); ^ MongooseError: Operation `urls.insertOne()` buffering timed out after 10000ms why im getting this error? can someone help please?
@amanbhatt1087
@amanbhatt1087 5 ай бұрын
bhai agar null wali error aa rhi hain toh upr bhai n source code diya hain usko copy marke console m entry print karana error dikh jayegiii tumkoo tumhari.. thanks me later.. bye
@dpxy1599
@dpxy1599 3 ай бұрын
ban gaya
@Vivek-tr8ji
@Vivek-tr8ji 8 ай бұрын
Path is required like error can be solved by defining default:shortid() , in shortId: Schema shortId: { type:String, unique: true, default: shortid(), required: true, },
@SUBZERO-vx7xs
@SUBZERO-vx7xs 3 ай бұрын
Thanks bro , was stuck on that thing for hours
@user-tw5jz5dv9t
@user-tw5jz5dv9t 5 ай бұрын
Bhai kisi ko is theme ka name pata ho to batao yrrrr
@VermaCoder
@VermaCoder Ай бұрын
bro no doubt.. you have knowledge in this... but you teach so fast.. any beginner who wants to learn from your series can't catch easily.... disappointed by this.
@user-ex6rm8ok9o
@user-ex6rm8ok9o Ай бұрын
so fast
@thebishalpaul
@thebishalpaul 11 ай бұрын
Solution for this error: TypeError: Cannot read properties of null (reading 'redirectURL') Don't miss out typing along with the url during post request. Hopefully it should work. Worked for me.
@comparisondata2473
@comparisondata2473 9 ай бұрын
bro i did the same wrong mistake , found later though 😂😂😂
@thebishalpaul
@thebishalpaul 9 ай бұрын
@@comparisondata2473 😂😂
@nityaranjan6714
@nityaranjan6714 9 ай бұрын
means what should I use and where?
@cws20128
@cws20128 7 ай бұрын
not working !
@anandsingh1367
@anandsingh1367 4 ай бұрын
​@@nityaranjan6714 hello bro have you found the solution for this
@hrithikjoshi4587
@hrithikjoshi4587 2 ай бұрын
Why is all the talk about a short id library and adding extra dependency for a small work. Use below function function generateRandomString() { const length = 8; const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; let result = ''; for (let i = 0; i < length; i++) { result += chars.charAt(Math.floor(Math.random() * chars.length)); } return result; }
@javabrain8480
@javabrain8480 2 ай бұрын
i copied and pasted your code but still getting error. What should i enter in the argument shortID inside await function?
@hrithikjoshi4587
@hrithikjoshi4587 2 ай бұрын
@@javabrain8480 your id will be the result of above function, execute above function and store it in a variable
@User-yb3yc
@User-yb3yc 4 күн бұрын
Nice bro it worked 🎉
@rajatjana2513
@rajatjana2513 7 ай бұрын
there is some problem with the code when i try to store a url which doesn't starts with "" or "" it works fine but when i try shout url it behave unexpectedly . Even the code provide by you has the same problem. But when a url starts with "https:" or "http:" this problem surprisingly doesn't happen. ‼edit: it is the res.redirect( ) , it needs a protocol like http or https otherwise it consider the redirect as a relative path so just append https before the url that stored in your database if it doesn't have any protocol to to that you can use the code here: const redirectUrl = url.redirectUrl.startsWith('') || url.redirectUrl.startsWith('') ? url.redirectUrl : `${url.redirectUrl}`;
@cryptogita8699
@cryptogita8699 7 ай бұрын
Bro you solve my problem, but I have 1 more problem I'm not getting code autocomplete or my vscode intellisense is not working for MongoDB what should I do?
@priyajha3700
@priyajha3700 6 ай бұрын
I was hung up on res.redirect() problem from a day! this was a big help
@sachinandanprasad7618
@sachinandanprasad7618 8 ай бұрын
Help Please, Cannot GET /analytics/0AOgMEv
@sankalpnaik877
@sankalpnaik877 6 ай бұрын
Resolved??
@kaustubhjoshi9022
@kaustubhjoshi9022 6 ай бұрын
if getting this error -> res.redirect(entry.redirectedURL); ^ TypeError: Cannot read properties of null (reading 'redirectedURL') at D: ode js\URL-Shortner\index.js:<a href="#" class="seekto" data-time="1642">27:22</a> at process.processTicksAndRejections (node:internal/process/task_queues:9<a href="#" class="seekto" data-time="305">5:5</a>) Node.js v18.16.0 [nodemon] app crashed - waiting for file changes before starting... solution - res.redirect('' + entry.redirectURL);
@snehamaurya3659
@snehamaurya3659 5 ай бұрын
thankss can u tell me how you got this solution?
@KirtanPatel552
@KirtanPatel552 5 ай бұрын
Same Here If You Have Any Solution Than tell me ...
@pranjalmaurya3832
@pranjalmaurya3832 4 ай бұрын
Did u got the solution?
@mkmihirkalbende2622
@mkmihirkalbende2622 3 ай бұрын
Thank You Brother!!
@cws20128
@cws20128 7 ай бұрын
TypeError: Cannot read properties of null (reading 'redirectURL') , Anyone please help how to resolve it.
@pragatiailani7206
@pragatiailani7206 7 ай бұрын
try res.redirect('' + entry.redirectURL);
Server Side Rendering with EJS and Node.JS
25:24
Piyush Garg
Рет қаралды 55 М.
Model View Controller in NodeJS | MVC Pattern
23:01
Piyush Garg
Рет қаралды 73 М.
WHO DO I LOVE MOST?
00:22
dednahype
Рет қаралды 78 МЛН
Универ. 13 лет спустя - ВСЕ СЕРИИ ПОДРЯД
9:07:11
Комедии 2023
Рет қаралды 6 МЛН
Connecting NodeJS with MongoDB | Mongoose + Express
19:18
Piyush Garg
Рет қаралды 87 М.
Building Node.js Authentication from Scratch
39:09
Piyush Garg
Рет қаралды 115 М.
Top 7 NodeJS project ideas to put in your resume
18:43
Sanket Singh
Рет қаралды 23 М.
Deploy NodeJS Application on AWS - Amazon Web Services | NodeJS
19:51
Creating Discord Bot in NodeJS
21:45
Piyush Garg
Рет қаралды 33 М.
JWT Authentication in NodeJS
14:30
Piyush Garg
Рет қаралды 73 М.
WHO DO I LOVE MOST?
00:22
dednahype
Рет қаралды 78 МЛН