Project Setup - Node.js/Express/MongoDB Course #1
HTML-код
- Опубликовано: 13 сен 2024
- In this video we will be setting up the base of our project by:
1. Setting up Express
2. Hooking up MongoDB
3. Setting up local ENV variables
4. Creating a base layout HTML file
5. Setting up our MVC folder structure
MongoDB Atlas:
mbsy.co/mongod....
How To Install Node.js:
• Your First Node.js Web...
How To Install MongoDB:
• How To Install MongoDB...
Learn Git In 20 Minutes:
• Learn Git in 20 Minutes
Code For This Video:
github.com/Web...
Previous Video:
• MVC Explained in 4 Min...
Next Video:
• Author's Index/Create/...
Playlist:
• Full Stack Web Develop...
Twitter:
/ devsimplified
GitHub:
github.com/Web...
CodePen:
codepen.io/Web...
#Node.js #FullStack #MongoDB
to those error
src.toString().split(NEWLINE).forEach(function (line, idx) {
^
TypeError: Cannot read property 'toString' of undefined
try it require('dotenv').config();
this works for me ...
Thanks for posting this fix.
Thanks worked with me as well.
Thanks, this worked for me too.
Thanks mate! Worked like a charm.
if (process.env.NODE_ENV !== 'production') {
require('dotenv').config();
}
place that at the top of your server.js
You described in 30 minutes what my professor couldn't clear describe in 3 weeks! Awesome!
That's why the professor didn't have a real job with a suitable salary.💸
Real teachers🧑🏫are people that are competent in the field they're trying to teach and had real experience & knowledge in it.
The solution to this worldwide🗺problem is to teach all the needed knowledge by yourself.
💪Use the power of the internet.
Better than Meta explained it
Awesome series! I love that you explain in detail why you are doing what you are doing in every step, including explaining the errors you will get by not taking the step correctly.
Many people do not do that. Thank you for doing that.
At server.js I had to add
if (process.env.NODE_ENV !== 'production') {
require('dotenv').config();
}
rather
if (process.env.NODE_ENV !== 'production') {
require('dotenv').load()
}
now I'm connected to mongoose and get "Connected to Mongoose"
Thanks Kyle you are my best teacher !
I know it's 2yrs late, but that worked for me
thank you, this was very helpful
The world need more people like you, im decided to be like you someday teachinh others for better wordl
Thank you! That really means a lot to me. I am sure that you will be an amazing teacher one day!
Just wow. Amazing amazing amazing! You simply explain complex things. Eagerly waited for the entire series including session, cookies, authentication, server side and client side validation on Express.
I hope you enjoy the rest!
OH YEAHHH! Who else is pumped for this series? 🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥
I know I am!
I am!
such an epic video!!
I'm late but YEAAAAASSSS I AM!!
I feel like I could watch this video 50 times over and just keep learning something new, amazing job, Kyle!
Thank you!
Great work mate #WDS, Keep it up
If you're facing an error with dotenv at 16:40, change require('dotenv').load() to require('dotenv').config()
thank u very much man
thank so so much
thanks a lot!!!
thank you!
thanks man, helped a lot
Learning to build websites has never been so much easy and fun. Thank you, Kyle! :D
Kyle your the GOAT. Absolutely amazing and well detailed.
just a small note in this fantastic lecture! I think it is in Feb 2024 require('dotenv').config() instead of .load() or .parse() at timestamp 16:35
tysm
Just another Error Correction for everyone, the .load() has been removed from dotenv , rather .config() has replaced it.
You just saved me! Thank you
thks u save me minutes
really bro...i've been searching for this since 2 hrs...trying to remove the error...thanks alot bro
@@deepak10995 Thank you!
oh Thanks from 2021
@Kyle you are the GOAT of dev education. I don't know how you do it but you put everything so clearly together. I even understand Express now as well because of another on of your videos. I would love your javascript , but I'm a broke student...But I loved your Learn CSS course. Thanks for all the great content!!
I came from Laravel so all the MVC stuff was easy to understand and now I'm starting to learn web development in node. Thanks Kyle
Just came from the videos on how the backend works, what is REST, & MVC explained. I’m loving how well put these explanations are!
Following you for the past month.. wat a mannnnn you are.. HATS OFF
Hey Vijay! Are you a 2021-graduate? Would you be interested in exploring job opportunities in web development currently?
for anyone doing this getting an error with "git push heroku master"
"error: src refspec master does not match any
error: failed to push some refs to"
you need to change the command to "git push heroku main"
Thank you my friend.
^ This will fix it. Github changed the primary branch name from master to main recently so that is why.
Thank you James.
Thanks a lot!
OMG i love you
You finished me with this awesome video.
I have to re watch it again and again until I absolve all of its value.
Learned more with you in 5 mins than in a week with everyone else
That's great Kyle!, Thank you!
For those who gets error with 'dotenv' dependencies from heroku --tail.
Try to move "dotenv" from "devDependencies" into "dependencies" in package.json.
Thank you - This worked for me!
Same! Thanks for the tip
Really well put together! It's nice with a series too that combine several technologies into a more complete project
Thanks! I am glad you are enjoying it.
Thank you very much dude! Instead of going to the tutorial hell, I'm learning nodejs with your pragmatic and very well explained courses! Thank you!
Thank you so much. I've been learning a lot throught your videos. Also the free options for hosting are a great bonus. Really appreciate all your content. Thank you again!
Hello Aniruddha! Are you a 2021-passout and looking for job opportunities in web development currently?
I have been a great fear about full stack development and you just made it's so easy 🙏🙏🙏
Hey Saurav! Are you a fresher in web development and open to job opportunities in full-stack development?
One of my favorite moments in the videos is when I spot an error and I'm waiting to see you get stuck and frustrated (like I always do), but then you casually fix it in 2 seconds :D
amazing video. I really like how you define the production part. That really clears the confusion when it comes to deployment. Thank you very much 😃
I'm glad you enjoyed it. I know when I was first learning web development the process of deployment and what to do for production really confused me, so I wanted to cover these topics at the very beginning of the project.
@@WebDevSimplified same problem i am facing but thanks to you i am more confident 😄
I have been able to follow along with you, but I don't really understand it. Is this a good way to learn? Will it eventually start to make sense?
For those for whom the `require('dotenv').parse()` related error persists despite changing it to `require('dotenv').config()`, try deleting your .env file and creating it again - this worked for me.
It also worked for me!!!! Almost tried everything and at last tried this solution and it actually worked. Thank you so much. however i did not understand the reason.
Thank you so much! Do you know why this works?
Thanks man really appreciated it!!!!
simply amazed of the simplicity and your explanation
Thank you! I am really glad I could help.
Awesome video, bro! You go straight to the point. Very clean code and minimal code to deploy the application, it's a really good first video tutorial! Thank you a lot.
Thanks for this. Just followed this all the way through and it's still applicable bar a few small changes that were fairly easy to remedy. I see the require('dotenv').config() is in the comments already. The mongo db atlas set up has changed ... it asked for an IP address but you can put 0.0.0.0/0 and create a cluster. Then when you connect you get the "connect to app" box shown in the video from which you can grab the connection string.
Learned tons, still relevant, and operational in 2021.
Thank you very much Kyle. You tutorials keep making me a better developer.
After pasting the password its still showing Application error for me..Please someone help me
If you're getting an error when loading up MongooseDB that says "MongooseServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017" - then go to your .env file and change it from "localhost" to "127.0.0.1" and it should fix the issue.
hi did that still getting the same error can you help
thank you so much mate! it works!
Thank you very much bro....I could not fix it for two days!
ahhhhh thank you so much!
Error: No default engine was specified and no extension was provided. Getting this error and im very confused. Trying to make a login in page but data is stored in MongoDB
Very straight forward tutorials nothing timepass must recommended.
I just realized that you sound a bit like Jared in HBO's Silicon Valley, as if he took on the role of coding, like Dinesh and Gilfoyle. I can't unhear it!
You have the best way to explain each step, keep going 💜
For anyone facing issues with Heroku deployment, check the Error Log via the CLI using the following command ~ heroku logs --tail .
Step 1 : Check Your DATABASE_URL, it would be correct but just be sure,
Step 2 : Check your start script as Heroku runs in a production environment by default so it does not install the dev dependencies.
make sure the following is the way your start script is setup.
"scripts": {
"start": "node server.js",
"DevStart" : "nodemon server.js"
}
Step 3 : is the error log says something like
2020-12-04T08:35:25.386313+00:00 app[web.1]: throw err;
2020-12-04T08:35:25.386314+00:00 app[web.1]: ^
2020-12-04T08:35:25.386314+00:00 app[web.1]:
2020-12-04T08:35:25.386314+00:00 app[web.1]: Error: Cannot find module 'mongoose'
Just Copy these from devDependencies to dependencies in your package.json file.
I made this comment in hopes to help you avoid the time it took me to debug this issue.
very detailed solution, thanks man👌🏻
can u tell what should be the DATABASE_URI is it from mongodb atlas url?
I have a question, at 8:15 you are writing :
🔰
app.use('/', indexRouter ); what is this slash purpose here ? We already said in the index file in router folder that if any request comes from / folder then send "Hello world".
🔰
then why do we need to write again "/" in app.use method.. what is it actually doing here ?
Incredible course! Greetings from Argentina.
Too good man!!..Simply amazing
Understood each and every step!
Hey Rushabh! Have you completed many tutorials in web dev such as this one? Are you a 2021-passout and open to job opportunities in web development currently?
thanks big time man.
really straightforward explaination and I actually learned something.
I've done heroku years back then I forgot... wasted skill. Many thanks for your video. I envy your so cool hair.
23:04 "and thats all it takes" LOL he explained in 23 mins but i took 2 hours even with his tutorial lmfao
Why does heroku still showing error even though i connected it to mongodb atlas? Please help
Error: 'The `uri` parameter to `openUri()` must be a string, got "undefined". Make sure the first parameter to `mongoose.connect()` or `mongoose.createConnection()` is a string.'
Fix: require('dotenv').config({ path: '.env' })
i got the same error but even i ve replaced it the error still occuring
what should i do
it hasn t been fixed for me
@@houssemkhi5036 in place of DATABASE_URL use mongodb://localhost/mybry
make sure your .env file name is '.env' and not just 'env'
(dot in the beginning)
Do you recommend using this folder as a boilerplate server for every website? I'm trying to think about why not but you'd probably know
For those who are unable to host on Heroku instead of following all the steps.
Try moving dotenv to dependencies from dev dependencies by running the command --> npm install dotenv --save-prod
Hopes this will help!!
Hey Piyush! Thanks for the tip! Are you a 2021-passout and interested to explore job opportunities in web development currently ?
Hi Piyush, I did as you've mentioned but it still doesn't work ... can you tell me why..?
@@shristi9149 do u find any solution?
Got it working. had to add .config() as suggested but also had to grant the proper permissions on installation then received the generated URL from compass. Thank you. Ensure Proper Permissions if compass not generate code under local (left sidebar).
Upate .env file DATABASE_URL= PATH_TO_MONGO_COMPASS_GENERATED_CODE.
If you are having error about connecting to mongoose then open window power shell(admin) , type mongod , and then save the code , it would work
Hello Ankur! Are you a 2021-passout and looking out for full-time positions in web development?
Amazing tutorial, very clear at explaining things. I Just subbed!
Thank you!
I am getting an Internal Server Error on my heroku app and I think it might have something to do with my mongodb. Everything works fine locally at this point but on heroku it does not. I think it may be because atlas cluster connection string is requiring a dbname and this video automatically shows the the dbname to be test. What should i do? I tried making the dbname 'test' in the connection string and it didnt help. Any help would be appreciated - thank you.
??could you find any solution
Ty for making web dev simple!
It's impossible to start a Heroku App without credit card right?
these are the types of videos that i want to watch
I'm glad you enjoyed it.
Everything is great until i try to deploy to heroku. i keep getting "application error". i have gone over everything 3 times and built the database on cloud atlas (i also dont have the option to see a free tier). frustrated because everything else is working perfectly. its a great set of videos. any help would be great if possible
actually you need to set the environment variables
amazing tutorial, great job explaining the details. Just subbed!
Thank you!
Mann I just know one thing You're super Awesome!!!!!
Thanks!
I am having an error on the its not working. It says it cant find an index folder
Mine too same problem
@@growthhacking9126 I got the solution go to web devs github and just copy paste the code then it will work I dont know why its like that
thanks kyle for these videos!
These videos are awesome! I have one question though, my tags don't autoclose like yours seem to do. How did you get that to work? Thank you!
He used an extension in vscode called "EJS Language Support"
I need this project but with MySQL.......can you help ?????
GENIUS!! thank for this video
on mongoose connect :
.set("useCreateIndex", true)
.connect(CONFIG.DB, { useUnifiedTopology: true,useNewUrlParser: true })
How to use this , I mean in which file I have to put this?
I'm at a standstill...as in the rest api project I am now getting this error and can't proceed. Can anyone offer advice? Thanks!
MongooseServerSelectionError: connect ECONNREFUSED ::1:27017
Word to others: I struggled for a long time to deploy this app to Heroku. Eventually I realized that no buildpack was in use. To find if you are in this situation, run:
>heroku buildpacks
To use the official buildpack, run:
>heroku buildpacks:set heroku/nodejs
Once I did this, the app worked as expected.
Thank you so much dude, could not figure out why it wasn't pushing for the life of me.
Absolutely Great!
Hey Saurav! Are you a 2021-passout and open to job opportunities in web development currently?
First video watched, instant sub :D
Big fan of your content WDS :thumbsup:
Keep it up!
Personal Use
Initialize Server 0:00 - 5:30
Initialize Controller/Index/Route 5:30 - 9:30
Initialize View 9:30 - 12:00
Initialize Model/Database 12:00 - 16:52
Initialize Git/Version Control 16:52 - 19:13
16:46 - Not getting the console log of "Connected to Mongoose" - any advice?
Can you explain why we use the body variable at 11:15 where is body variable defined in expressLayouts? Because if we are sending like json we would put the json variable name but body is not explicitly defined anywhere
Hey Kyle. Thank you so much for this great tutorial. Is ejs is solving the same issues the font end framework (react, angular, etc) solve ?
Do you have a full stack tutorial corporate node.js with react for the front?
Thanks!
Might sound like a stupid question but how do you already have Github in the Explorer upon start up of VSC?
Hello I am having trouble, my mongo wont connect error message: UnhandledPromiseRejectionWarning: MongooseServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017
I faced same issue the problem is that the MongoDB server is not running. So run this command on your terminal.
sudo systemctl start mongod
then run mongo on terminal
supremely helpful
How can I hook this up to vercel instead of heroku? Heroku is no longer free.
Make sure your DATABASE_URL is 0.0.0.0 instead of localhost if you are having issues!
not working for me
this worked for me
Thanks man
thanks
I finally got it to work on Heroku guys!!... I was getting the `openUri()` must be a string, got "undefined" error. I want to share some key pieces of code with you. On server.js:
if(process.env.NODE_ENV !== 'production') {
require('dotenv').config({ path: '.env' })
}
also:
mongoose.connect(process.env.DATABASE_URL, {useUnifiedTopology: true, useNewUrlParser: true, useCreateIndex : true})
My .env file in VSCode is still set to: DATABASE_URL=mongodb://localhost/mybrary
I signed up for Heroku and installed the Heroku CLI. I created an instance in Heroku and set the password as Kyle says near the end of the video, but still got the error. I added my code above, did a couple of git pushes and somehow I ended up with a SECOND instance on Heroku. That second instance ,which I did not even know was there, did not have the password set. So once again, I set the password as Kyle said and BOOOOOMM. It worked.
Make sure you set the password on the right instance in Heroku.
Super! Thanks Man this helped me get through although im stil getting promise issues and unhandled errors i think this is enough for me to go on with the tutorial thanks again.
Absolute genius ! thanks for the help
Here i have problem
during the connection
mongodb+srv://user:@cluster0-odq2w.mongodb.net/?retryWrites=true&w=majority
what should i need to write the there is n't anything i tried a lot but it doesnot load on heruko app
I have the same problem, found a fix for that?
that is the exact issue i have right now
i am curious if you solved it
@@barotube24 anyone solved this?
@@dangeddes855 The is what you have set in .env file!
Hey man this is an awesome video! Thank you! I seem to be having an issue with the express-layouts part. It won't render the main layout.ejs only the index.ejs. Going off the express layouts docs I even tried specifying a specific layout to use with no luck. My file structure and setup is identical to yours. Any ideas? I don't know what I'm missing.
I'm also having problem with this. Does any can solve this?
@@v.michaelangelopaster943 You need to download extension EJS language support
How can I do some exceptions for the ejs-layouts? To either use another layout file or to just render a html file?
Simply Great
parse() did not work for me so I used config() and worked. :)
Am I the only one that feels like learning Node.js with the main modules feels like learning a new language
failed to lookup view "index" in views directory :(
hey!, i was getting the same error, try on server.js line 7 this app.set('views', __dirname + '/views') the '/" on views fixed my problem
Enjoying this course so far--really helping to clear some things up for me. Just out of curiosity--is there a reason you're using EJS over Handlebars? I'm in a boot camp and they're teaching us Handlebars so I was just wondering the difference/why you picked that one. Thanks!
I choose EJS since I think it is most similar to HTML so it would be most familiar to people that have never used a templating language before. You can use whichever language you prefer.
@@WebDevSimplified Thanks for the clarification!
I am doing the exact stuff...but still app is not working.!
Is it because I am having my app-directory as a subdirectory in my repo? So shall I take my app-directory to some independent repo?
Hello Vishal, have you created many projects in web development? Would you be interested in exploring job opportunities in web development currently ?
What should be provided instead of in mongodb atlas connection string? Please help..
just delete that part... it will work without it
Hello Athul! Are you a fresher in web development - 2021passout? Are you looking for job opportunities in development currently?
@@shivanigaddagimath2143 I am 2022 batch
@@nathulkumar3368 I see. If you are open to full-time job opportunities or if you have seniors who are looking for an opportunity in web development, you can connect with me on linkedin to know more about this opportunity. Find my LinkedIn URL on my channel.
@@shivanigaddagimath2143 Sure
Use main instead of master if you have problems with the heroku part
Why no need to configue the mongodb atlas now? after I push the main to heroku, everything works well for me, the app can be accessed with no errors?
Im not in need for my app to be accesable on the internet, I just need to be able to run it to show my teacher it. Do i still need the heroku part or can i ignore it. Very helpfull series thx!
Hey man just curious you are not using any semicolons, how did you setup your environment for this?
great and simple, thank you so much
You're welcome!
An error kept popping in vs code console - "mongodb-connect-econnrefused-127-0-0-127017" // to resolve this, use reveal var link(used in heroku) --> copy-paste it in DATABASE_URL of .env file in vscode project.
PS: this connects mongodb atlas with our project
Hello Kyle, please can you do a nodejs chat server for real-time chat. You explain things in such a easier way.... respect
We need tutorial like this like water