express-locallibrary-tutorial | Local Library website written in NodeJS/Express ; example | Runtime Evironment library
kandi X-RAY | express-locallibrary-tutorial Summary
kandi X-RAY | express-locallibrary-tutorial Summary
Local Library website written in NodeJS/Express; example for the MDN server-side development NodeJS module:
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Creates a new book instance
- creates the author authors .
- Create a book
- Create a new book
- Create a new book instance
- Create an author
- Create a new group
express-locallibrary-tutorial Key Features
express-locallibrary-tutorial Examples and Code Snippets
Community Discussions
Trending Discussions on express-locallibrary-tutorial
QUESTION
As I'm currently learning coding with express/Node in order to evolved (used to C and PHP/MySQL...) I have completed the MDN tutorial on express which very well done and every thing is pretty much straight forward; my personnel project is going almost done, thanks to the Mozilla teaching team.
However, here is a point I still can't figure out as I'm still not confortable with the use of Callbacks function. The point of dealing with asynchronous timing of execution I get, but using MongoDB and mongoose in this tutorial, I've got that queries can be executed either in two steps or in one go by using directly a callback function like creating an instance of a Schema:
...ANSWER
Answered 2021-Jul-08 at 02:52Welcome to stack
in Js world , the function can be treated as a variable , the function is a type of variable like String , Number …etc , which may confuse you .. the callback is just a function that has a variable ( argument ) name … now swift language has implemented that pattern as well .
The functions in JS could be sent to other functions as an argument and could be returned as well.
The callback argument sent by the function caller like any other variable sent to the called function but sent as a function …
You could name it anything like cb or whatever … The cb argument is a function which means when you try to use it inside the called function it may need arguments as well like cb(null, author)
.. Now imagine the cb
is just a variable of type function sent from the caller to the called function.. and the cb itself as a function has to receive arguments .
I know it’s confusing especially if cb is returned as well .
Sometimes callbacks don’t receive any arguments , Again you may call them anything like callback or cb as a convention .. Usually they are the last parameter, as a convention … It just needs some imagination to understand how this confusing parameter goes in and out …
Inside your called function if you didn’t use your callback so removing it will not affect the code as you will not examine errors . BUT in node world callbacks are usually important because it does something after you finish what you’re doing .
i hope that simple illustration clarifies what you’re asked because it has confued me a lot like you .
QUESTION
I tried to setup and use Mongo Atlas using the setup steps of the section Setting Up the Mongo db database ,in the Mozila Express tutorial that you can find here, then I got authentication error when running the populatedb.js file mentioned in that tutorial:
...ANSWER
Answered 2021-May-11 at 00:17I solve the error now, it is actually that you can create a user and password for a created database. And so I was using the username and password for the Atlas website and not that of the database itself. New that I created a new database and username and password for that database, I could use that database for my app and it worked fine!
But the steps that i used to arrive at the solution is not straigh forward. I actually started looking at how to implement a search engine for the mongoDB database and found a tutorial that ask me to connect via the mongoDB compass. I used the mongoDB compass to connect with the atlas username and password and it didn't work. but then I was like, this can't be possible. Then i removed the password completely and it seems to connect!.
Afterwards, I also tried again the Express tutorial and remove the password but it still give cannot have empty string password error. But then I was like I'm just gonna create a new account. and try it out. When I created the new account and the new database, they actually asked me to create a username and password for the new database! And this is where I found out that you also have a usernam and password for the created database.
I don't know what happen before, maybe it was cause I created the database long time ago and forget that a database uses a username and password as well.
SO it is solved and I'm moving on the 4th part of the tutorial.
QUESTION
I'm following the library website project on MDN but for some reason the book_list view gives an error on line 11. I have exactly copied the code from MDN as in the link below. If I comment line 11 the view renders as below but the author names do not appear which is the desired result as you will see in the MDN link get a list of all Book objects in the database:
Here is the github link: https://github.com/mdn/express-locallibrary-tutorial
I get the error: /Projects/API/express-locallibrary-tutorial/views/book_list.pug:11 9| li 10| a(href=book.url) #{book.title} > 11| | (#{book.author.name}) 12| 13| else 14| li There are no books. Assignment to constant variable.
...ANSWER
Answered 2020-Jun-11 at 23:53After reviewing my code with MDN again, I noticed in my code I had declared the variable fullname in the author model using const which was causing the issue. Using let or var to declare the variable fixed the issue.
Have to revisit on var, let and const
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install express-locallibrary-tutorial
Set up a Nodejs development environment.
Once you have node setup, enter the following commands in the root of your clone of this repo: npm install DEBUG=express-locallibrary-tutorial:* npm run devstart #For linux
Open a browser to http://localhost:3000/ to open the library site.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page