From my observation, people are having issues with query at 14:30 not running / Cannot read property 'create' of undefined. 2 things to watch: 1) In your index.js make sure you have .filter(file => file !== "index.js') and not .filter(file => { file !== 'index.js')) 2) Try using const model = require(path.join(__dirname, file))(sequelize, Sequelize) instead of const model = sequelize.import(path.join(__dirname, file)) Another thing you might want to watch: 1) version compatibility of your node and sqlite 2) for message: "please install sqlite3 package manually", I'd suggesting uninstalling sequalize and sqlite and running: npm i sequalize sqlite3
Another thing to watch is Joi. You must install npm install @hapi/joi as the previous version of Joi has been deprecated. Change the schema and validation to below this: const schema = Joi.object({email: Joi.string().email}, password: Joi.string().pattern(new RegExp('^[a-zA-Z0-9]{8,32}$'))); And for error use const { error } = schema.validate(req.body)
A couple of videos in and enjoying this series, thank you. Like the well paced instruction, demo and recap approach taken, and the fact you are taking time to show an iterative dev workflow with git, linting, tidy project setup and building on a SQL db.
For those who are starting there journey here please realize this is an old video, secondly an error that had me pulling my hair for a bit was ".create" is not a function, however it can be fixed by returning the User in user.js and by using this line : const model = require(path.join(__dirname,file))(sequelize, Sequelize.DataTypes) , in index.js this will fix your issues with that as of 2023 sequelize, hopefully this helps someone. Keep on keepin on
Thank you for an impressive effort in this entire series of films. Real-time programming/execution with constructive and clear explanations and examples. Most educational sources are rewarding solely depending on how much you want/are willing to learn. Those who did not like the movie/series would simply continue to watch cute kittens, sell cars/insurance, or whatever they are really doing ...
For anyone having issues when working with the regular expressions during the validation with Joi. Try replacing the single quotes ( ' ) with a forward slash ( / ). Had this problem when working with Nuxt recently.
I was fixing error “sequelize is not a function” after googling I find the solution, I just replaced declare of model on line 20 with these: const model = require(path.join(__dirname,file))(sequelize, Sequelize.DataTypes)
While repeating got an error “Joi.validate is not a function” This is how I made it work: first of all I changed declaration of schema like const schema = Joi.object({ email: Joi.string().email(), password: Joi.string().regex( new RegExp(‘^[a-zA-Z0-9’{8,32}$’) ) }) Then I changed validation const {error} = schema.validate(req.body)
kind remainder for using newer version of Joi, Joi.validate() is being replaced by: const schema = Joi.object({ name: Joi.string().min(6).required(), email: Joi.string().min(6).required().email(), password: Joi.string().required() }); const validation = schema.validate(req.body); res.send(validation);
At 14:20 if you get a warning saying "sequelize depreciated String based operators are now deprecated. Please use Symbol based operators for better security" just put "operatorsAliases: false" in the options section of your config.js file.
can you plz provide detailed codes for config.js, we firstly included sequelize above using const Sequelize = require('sequelize') and then we used it like this: const sequelize = new Sequelize( config.db.database, config.db.user, config.db.password, config.db.options ) so how may the above codes be changed to solve the issue?!!
If you are an idiot like me and the policy doesn't seem to apply to your request - check that you passed "AuthenticationControllerPolicy.register" before "AuthenticationController.register" in your route.js file. That took me a few hours to understand that the policy was interacting AFTER the data is sent in JSON to the REST Api. No wonder the policy won't be applied! Now I can relax, until the next error :D
TypeError: Cannot read property 'create' of undefined *Thanks for taking the time to put together this fantastic Vue.js video series. *At 21:45 getting the following TypeError when attempting to POST (using Postman): *All required packages are installed and available. *I read and tried solutions in the current posts, but no luck. User.js ------- module.exports = (sequelize, DataTypes) => { //return sequelize.define('User', { //Tried this without 'return User;' below, but no luck. const User = sequelize.define('User', { email: { type: DataTypes.STRING, unique: true }, password: DataTypes.STRING }); return User; } AuthenticationController.js --------------------------- const {User} = require('../models'); module.exports = { async register (req, res) { try { const user = await User.create(req.body); res.send(user.toJSON()); } catch (err) { console.log(err); res.status(400).send({ error: 'This email account is already in use' }); } } }
at 13:47 I am getting the error after running 'TypeError: Cannot read property 'name' of undefined' in reference to 'db[model.name] = model' which makes sense to me, idk where it would come from
the reason is the function in 'User.js' do not return the model, here is the corrent way: module.exports = (sequelize, DataTypes) => { const User = sequelize.define('User', { email: { type: DataTypes.STRING, unique: true, }, password: DataTypes.STRING, }); return User; };
The function in the video does in fact return the model, but it's written in a lesser known standard. It is implicitly returning the result of the sequelize.define() method. module.exports = (sequelize, DataTypes) => sequelize.define('User', { email: { type: DataTypes.STRING, unique: true }, password: { type: DataTypes.STRING } })
issus that i found by practice is : sequelize.import was debaraced so should be changed with require changed : const model = sequelize.import(path.join(__dirname, file)); to const model = require(path.join(__dirname, file))(sequelize, Sequelize); also we should change User.js and return function because its give undefinded module.exports = (sequelize, Sequelize) => { const User = sequelize.define('User', { email: { type: Sequelize.STRING, unique: true }, password: Sequelize.STRING }) return User } thank you
I’m new to the whole full stack world, typically I just make programs with c, c#, Java, and I got a question. Is it normal to build web applications with so many dependencies? Just looking at your folder node-modules you have like 100 other dependencies.
Two errors I was getting: 1) async function 'unexpected identifier' ~ this was due to node being outdate. Upgrade following these directions: www.hostingadvice.com/how-to/update-node-js-latest-version/#linux 2) 'install sqlite3 manually' ~ this worked for me: github.com/mapbox/node-sqlite3#building-for-node-webkit
At 25:00 you have both the Controller and Policy in the routes.js file. This file could grow fairly large, if you have lots of controllers and policies. Is there a better way to organize/refactor this? Maybe creating a separate file for each controller/policy pair, then including/requiring/importing them into the main routes.js file? Is this something you can show in the next part?
(node:5608) [ESLINT_LEGACY_OBJECT_REST_SPREAD] DeprecationWarning: The 'parserOptions.ecmaFeatures.experimentalObjectRestSpread' option is deprecated. Use 'parserOptions.ecmaVersion' instead. (found in "standard")
For the validation, you display each message separately, depending on how many errors you have, but is there a way to return all errors at once and highlight the fields with errors? Is this something you can show in the next part?
I am having an error in which constraints stated in User.js file is not been applied on my input. for Ex. Email should be unique, but it is even accepting duplicate emails. If anyone else also faced these errors kindly help.
Cody Seibert other tutorials I've seen seem to suggest (and I agree with this) that validation should occur at multiple stages. So you can validate through the database definition, in your controllers, and every step in between. The reasons I've seen given for this are that a) a client you don't control might connect to your back end but catching errors close to the UI gives better UX and performance, and b) not all types of validating are available at all levels.
This is my first time using anything SQL based. I normally use MongoDB and I use Joi's validation along with Mongoose's validation. So if I decide to actually use this app or use it as an example for something else I will definitely use sequelize validation rules as well.
Hello, thanks for the course. I have a problem with sequelize.import() he don't work and the website says he is deprecated i replace it with require but nothing. And if he don't work, i can't create a user , he send me an error like "can't read property create of undefined" the "undefined" is the User model we use to create a user. Thnaks
I had the same issue, I found that I was not returning the result of the filter condition. I was doing this: fs .readdirSync(__dirname) .filter((file) => { file !== 'index.js' }) instead of: fs .readdirSync(__dirname) .filter((file) => file !== 'index.js' )
Not putting the brace in arrow function means there is an implicit return, so if you put the braces in the arrow function, you need to explicitly give the return statement. So either this fs .readdirSync(__dirname) .filter((file) => file !== 'index.js' ) or this fs .readdirSync(__dirname) .filter((file) => { return file !== 'index.js' })
Great set of videos!! I am already quite a bit further through the videos than this part 2, creating the code along with the videos. But it occurred to me: I cannot figure out how the "updatedAt" and "createdAt" are being generated, for instance, at time 21:50. What library is automatically adding this to the payload? Is it getting added to the sqlite3 DB? We didn't add these columns to the database when creating the model. Thanks!
Thanks for the quick reply! I didn't realize that was done automatically. Now I see it here: docs.sequelizejs.com/class/lib/model.js~Model.html#static-method-init Again, great work!!
I am using MariaDB and I am getting this issue: throw new Error('Dialect needs to be explicitly supplied as of v4.0.0'); I tried a few things including adding dialect to my env in config.js but I am still stuck
great set of video, thankyou! i already have some difficulties to catch up the syntax e.g. double bracket: require('./route')(app) and variable with {} e.g. const {sequelize} and etc... where should I learn these? thankyou
require('./route') returns a function which takes an app. see www.tutorialsteacher.com/nodejs/nodejs-module-exports. You could do this and get a similar result const f = require('./route') f(app) The reason for this is that in routes.js you say module.exports = (app) => { // stuff here } require('sequelize') returns an object which has a sequelize property. In js, if you get an object, you can deconstruct its properties into separate things by putting property names into {}. see exploringjs.com/es6/ch_destructuring.html. In this case we're just interested in the sequelize property. You could do this and get a similar result: var s = require('sequelize') var sequelize = s.sequelize edit: * for bold didn't work so removed
Hi, thanks for another great video. Is there a reason to use routes and controllers? I started working with express.Router so I just have my routes folder and in each file just the functions involved with the route. Is it just a coding style question or does this approach have advantages? Thanks!
So far I'm amazed since the first part but on this 2nd part, I can't install sqllite3. The few last lines of the debug log goes like 2416 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:288:5) 2417 verbose pkgid sqlite3@5.0.1 2418 verbose cwd D:\Web\Vue.js\Web Apps\tab_tracker\server 2419 verbose Windows_NT 10.0.18363 2420 verbose argv "C:\\Program Files\ odejs\ ode.exe" "C:\\Users\\User\\AppData\\Roaming\ pm\ ode_modules\ pm\\bin\ pm-cli.js" "install" "sqlite3" 2421 verbose node v14.15.5 2422 verbose npm v6.14.4 2423 error code ELIFECYCLE 2424 error errno 1 2425 error sqlite3@5.0.1 install: `node-pre-gyp install --fallback-to-build` 2425 error Exit status 1 2426 error Failed at the sqlite3@5.0.1 install script. 2426 error This is probably not a problem with npm. There is likely additional logging output above. 2427 verbose exit [ 1, true ]
Hello, thx for this serie, really good job so far ! It's the first time I hear about sequelize, any reason why you prefer sequelize/sqlite over mongoose/mongodb ?
@@WesChege Ya, I did find the solution. But for me it was a specific code problem, in the index.js file in models, when we used the fs file system I accidentally put the code of the line 17 in {} braces, while returning file in the filter function :)
@@rishidusad2985 thanks mate, I have checked that but I don't think that's my problem though, when I call the register end-point I get this response error... { "name": "SequelizeDatabaseError", "parent": { "errno": 1, "code": "SQLITE_ERROR", "sql": "INSERT INTO `Users` (`id`,`email`,`password`,`createdAt`,`updatedAt`) VALUES (NULL,'test@test.com','test1234','2020-07-12 08:20:51.913 +00:00','2020-07-12 08:20:51.913 +00:00');" }, "original": { "errno": 1, "code": "SQLITE_ERROR", "sql": "INSERT INTO `Users` (`id`,`email`,`password`,`createdAt`,`updatedAt`) VALUES (NULL,'test@test.com','test1234','2020-07-12 08:20:51.913 +00:00','2020-07-12 08:20:51.913 +00:00');" }, "sql": "INSERT INTO `Users` (`id`,`email`,`password`,`createdAt`,`updatedAt`) VALUES (NULL,'test@test.com','test1234','2020-07-12 08:20:51.913 +00:00','2020-07-12 08:20:51.913 +00:00');" }
At 21:35 in the video, I get a syntax error ---- /Users/ekeyur/tab-tracker/server/src/controllers/AuthenticationController.js:4 async register (req, res) { ^^^^^^^^ SyntaxError: Unexpected identifier at Object.exports.runInThisContext (vm.js:76:16) at Module._compile (module.js:542:28) at Object.Module._extensions..js (module.js:579:10) at Module.load (module.js:487:32) at tryModuleLoad (module.js:446:12) at Function.Module._load (module.js:438:3) at Module.require (module.js:497:17) at require (internal/module.js:20:19) Did anyone have this problem? Everything was working fine before this.
I haven't been able to fix the problem. Could it be that I don't have mySQL installed on my computer. Do you guys have it installed? I only have postGreSql
Hey guys, I got this and eventually worked out it was due to having an old version of node on my machine (7.4.0 I think). Fixed by going to console and typing 'nvm install 8.4.0' (latest version to date)...
Sequelize has the weirdest versioning system I ever saw. A year ago they were on 4.8 and now they are on 4.38 lol Seeing their version history made me very suspicious for using this package , among other things.
What is the full version of the sqlite you installed? It is not installing on my machine. I tried npm install sqlite3 --build-from-source to for compiling it after installing node-pre-gyp --fallback-to-build but it is still not working
Hey I'm following your videos, but I'm having problems using Vuetify At first it is working partially, when using cyan for example I am not getting the color. I am receiving a warning message regarding v-flex saying that the component failed to resolve. I'm using vue3 and vuetify 3, I've tried everything and I can't get this thing to work correctly
I am a littel confused: What is serving the vue stuff? Usually I had in the backend a res.render("whatEver") which returns a view, but here, "npm run serve" serves the vue stuff, not express. Is that how this is run in production?
when doing validation I added two things I also allowed certain special characters and I told joi to look for two parts to the domain for the email. With out that someone could register with test@test and it would work. Now it requires test@test.com or .edu or whatever. so here is what my email verification looks like... email: Joi.string() .email({ minDomainAtoms: 2 }) and here is what my password verification looks like... password: Joi.string() .regex(new RegExp(/^[-@./#&+\w\s]{8,30}$/)) .required()
Just found this tutorial and wondering if anyone has completed it recently? I want to learn more about connecting Vue & Node to SQL databases but I'm hesitant to start it because of the many issues related to changes in sqlite & sequelize. Have you guys been able to solve these issues? I'm pretty comfortable with Vue and Vuetify so not worried about changes from that end.
Hadn't encountered the syntax ```const {error, value} = Joi.validate({ a: 'a string' }, schema);``` specifically referring to the left side. Is this ES6 syntax or just a thing specific to Joi? Also, if it's an ES6 thing I'd love it if someone had a link to documentation so I can read more :D
Am I the only one having a problem with getting a unique email constraint working ?! I've been looking for a solution and I think its a sequelize issue and I have to add some code for it to work queryInterface.addIndex() Did anyone else had the same issue ?! and about the error message, how can we change it dynamically so that it returns a message depends on the error
Vuetify.min.css is not being recognized in my app. This is an issue I don't know how to fix. everything was working and looking fine, but now no styles are presented once this has been imported. Also nodemon doesn't work now. any solutions?
I have the same issue. I found that at the index.js file should change .filter(file => { file !== 'index.js') } to .filter(file => file !== 'index.js'). Hope this help.
You figure it out? I ran into this too. npm un sqlite3 npm install --save sqlite3 npm install --save joi That did it for me. I had pinned sqlite3 to version 3.1.8 like he did in the video which was the problem.
I made a mistake while creating the User model and wrote eamil imstead of email which means that my table users has a column called eamil! how can I alter the user table and change the column eamil to email?
These add two new items to the db object which is what gets exported. db.sequelize = sequelize attaches the sequelize object we created in the file and db.Sequelize = Sequelize (make sure both have uppercase S, btw) attaches the Sequelize library which we import at the top of the file.
Hi, just started this great tutorial, but I stopped at 14:38. I am getting this error: 'Dialect needs to be explicitly supplied as of v4.0.0' I tihnk this is due to update in packages. can someone help me?
in your index.js file add the dialect there ..see code below... const sequelize = new Sequelize( config.db.database, config.db.user, config.db.password, { dialect: 'sqlite', storage: './ProjectX.sqlite' } ..the error says that u need to explicitly write that
How to deal with associations like belongsTo in the way models are imported in this code ? I added a prototype method to the models called "defineAssociationsUsingModels" that I call on each model with another forEach. What do you think ?
At 15:53 I have an error tab-tracker\server\src\models\index.js:8 database: config.db.database, ^ TypeError: Cannot read property 'database' of undefined
Great tutorial!!!... I just have a question, what if instead of using vuetify I want to use custom and different css and js external files for every file.vue? does anybody know whats the best approach to achieve this? Thanx!!!
To add css to a specific component try the following: your css goes here You can put this at the bottom of your file and styling will only apply to the component where the css lives. Don't think you need external js files, you should be able to put your js inside of tags when you build your "controller".
Great video here, but i am having problem installing joi.. giving me error and after the error, it crashes the server. so i have to re install sqlite and the server will work again. please how can i solve the joi not install.
I just found this tutorial and was thinking of going through it to learn more about connecting Vue & Node to SQL. I'm hesitant to because of the many issues related to changes in sqlite/sequalize. Have you guys been able to solve these issues? I'm pretty comfortable with Vue and Vuetify so no worried about changes from that end.
I am getting this error after setting up User.js and Index.js (Error: Please install sqlite3 package manually). I tried reinstalling all my npm modules. I double checked and it's saved in my package.json. I also tried using different versions of sqlite3. To no avail.
I ended up just using postgresql instead. Worked on first try and had to change minimal code. Great tutorial. This is exactly what I was looking for while on my way towards full stack development.
Seems unusual, I know, so I looked it up: "One of the goals of async/await is to make asynchronous code appear more syntactically similar to synchronous code. This is also true for error handling." www.syntaxsuccess.com/viewarticle/async-await-error-handling
Hello guys,,, has anyone experience this error -TypeError: sequelize.sync is not a function - with sequelize.sync function? ,.,, i've been stuck on it for the past three days and lastly have resorted to copying the app code from the Github repo and still would not compile cleanly.... any idea? thanks
Hello. I'm struggling to find out which part of script creates tabtracker.sqlite database? I deleted my db file and wonder how it has to be created. Appreciate if somebody can help!
From my observation, people are having issues with query at 14:30 not running / Cannot read property 'create' of undefined. 2 things to watch:
1) In your index.js make sure you have .filter(file => file !== "index.js') and not .filter(file => { file !== 'index.js'))
2) Try using const model = require(path.join(__dirname, file))(sequelize, Sequelize) instead of const model = sequelize.import(path.join(__dirname, file))
Another thing you might want to watch:
1) version compatibility of your node and sqlite
2) for message: "please install sqlite3 package manually", I'd suggesting uninstalling sequalize and sqlite and running: npm i sequalize sqlite3
Another thing to watch is Joi. You must install npm install @hapi/joi as the previous version of Joi has been deprecated. Change the schema and validation to below this: const schema = Joi.object({email: Joi.string().email}, password: Joi.string().pattern(new RegExp('^[a-zA-Z0-9]{8,32}$'))); And for error use const { error } = schema.validate(req.body)
@@kentarooka3459 You're a Star!
Thanks for choosing SQL db, hard to find tutorials using SQL.
A couple of videos in and enjoying this series, thank you. Like the well paced instruction, demo and recap approach taken, and the fact you are taking time to show an iterative dev workflow with git, linting, tidy project setup and building on a SQL db.
For those who are starting there journey here please realize this is an old video, secondly an error that had me pulling my hair for a bit was ".create" is not a function, however it can be fixed by returning the User in user.js and by using this line : const model = require(path.join(__dirname,file))(sequelize, Sequelize.DataTypes) , in index.js this will fix your issues with that as of 2023 sequelize, hopefully this helps someone. Keep on keepin on
Dude. U saved me from a frustrating debugging. XD
Thank you for an impressive effort in this entire series of films. Real-time programming/execution with constructive and clear explanations and examples. Most educational sources are rewarding solely depending on how much you want/are willing to learn.
Those who did not like the movie/series would simply continue to watch cute kittens, sell cars/insurance, or whatever they are really doing ...
This teaching would help a lot of us get a job. Thanks.
For anyone having issues when working with the regular expressions during the validation with Joi. Try replacing the single quotes ( ' ) with a forward slash ( / ). Had this problem when working with Nuxt recently.
I know, two years later - But thank you! I'd been going over this again and again.Awesome
I was fixing error “sequelize is not a function” after googling I find the solution, I just replaced declare of model on line 20 with these:
const model = require(path.join(__dirname,file))(sequelize, Sequelize.DataTypes)
It is giving me an error
require(...) is not a function
Do you have any idea how to fix it ???
@@beevlog402 Try to downgrade the sequelize version to something below 6.0 or use 'sequelize.define' instead of 'require'
While repeating got an error “Joi.validate is not a function”
This is how I made it work:
first of all I changed declaration of schema like
const schema = Joi.object({
email: Joi.string().email(),
password: Joi.string().regex(
new RegExp(‘^[a-zA-Z0-9’{8,32}$’)
)
})
Then I changed validation
const {error} = schema.validate(req.body)
thanks for the miniature stack overflow comment
thank you!
thank you !
You are the best the best the best
kind remainder for using newer version of Joi, Joi.validate() is being replaced by:
const schema = Joi.object({ name: Joi.string().min(6).required(),
email: Joi.string().min(6).required().email(),
password: Joi.string().required() });
const validation = schema.validate(req.body);
res.send(validation);
At 14:20 if you get a warning saying "sequelize depreciated String based operators are now deprecated. Please use Symbol based operators for better security" just put "operatorsAliases: false" in the options section of your config.js file.
use this bro.
const sequelize = new Sequelize(
config.db.database,
config.db.user,
config.db.password, {
dialect: 'sqlite'
},
config.db.options
)
In config.js:
const Sequelize = require('sequelize')
const Op = Sequelize.Op
db: {
...
options: {
...
operatorsAliases: Op
}
}
No help :F
can you plz provide detailed codes for config.js, we firstly included sequelize above using
const Sequelize = require('sequelize')
and then we used it like this:
const sequelize = new Sequelize(
config.db.database,
config.db.user,
config.db.password,
config.db.options
)
so how may the above codes be changed to solve the issue?!!
Thanks, worked like a charm :)
Great job!!! You have helped me a lot. Your teaching style is truly appreciated.
Thank You very much for using SQL as the backend!!!!!!
Would be really nice to have an alternative "Part 2" using objection.js :)
If you are an idiot like me and the policy doesn't seem to apply to your request - check that you passed "AuthenticationControllerPolicy.register" before "AuthenticationController.register" in your route.js file.
That took me a few hours to understand that the policy was interacting AFTER the data is sent in JSON to the REST Api. No wonder the policy won't be applied! Now I can relax, until the next error :D
TypeError: Cannot read property 'create' of undefined
*Thanks for taking the time to put together this fantastic Vue.js video series.
*At 21:45 getting the following TypeError when attempting to POST (using Postman):
*All required packages are installed and available.
*I read and tried solutions in the current posts, but no luck.
User.js
-------
module.exports = (sequelize, DataTypes) => {
//return sequelize.define('User', { //Tried this without 'return User;' below, but no luck.
const User = sequelize.define('User', {
email: {
type: DataTypes.STRING,
unique: true
},
password: DataTypes.STRING
});
return User;
}
AuthenticationController.js
---------------------------
const {User} = require('../models');
module.exports = {
async register (req, res) {
try {
const user = await User.create(req.body);
res.send(user.toJSON());
} catch (err) {
console.log(err);
res.status(400).send({
error: 'This email account is already in use'
});
}
}
}
I am having the same issue, did you figure out why?
Thank you for this amazing tutorial!
I'm imaging that you're sipping on some tea with your pinky finger in the air when you said "Models" at 19:38 :D Great tutorial though
who is this instructer and does he have his own you tube channel ? he is brilliant
Cody Seibert: th-cam.com/channels/srVDPJBYeXItETFHG0qzyw.html
at 13:47 I am getting the error after running 'TypeError: Cannot read property 'name' of undefined' in reference to 'db[model.name] = model' which makes sense to me, idk where it would come from
the reason is the function in 'User.js' do not return the model, here is the corrent way:
module.exports = (sequelize, DataTypes) => {
const User = sequelize.define('User', {
email: {
type: DataTypes.STRING,
unique: true,
},
password: DataTypes.STRING,
});
return User;
};
Thanks this helped me
TechSquidTV i
The function in the video does in fact return the model, but it's written in a lesser known standard. It is implicitly returning the result of the sequelize.define() method.
module.exports = (sequelize, DataTypes) =>
sequelize.define('User', {
email: {
type: DataTypes.STRING,
unique: true
},
password: {
type: DataTypes.STRING
}
})
That's if you omit the curly brackets.
awesome video tutorial series, thanks a lot!
issus that i found by practice is :
sequelize.import was debaraced so should be changed with require
changed :
const model = sequelize.import(path.join(__dirname, file));
to
const model = require(path.join(__dirname, file))(sequelize, Sequelize);
also we should change User.js and return function because its give undefinded
module.exports = (sequelize, Sequelize) => {
const User = sequelize.define('User', {
email: {
type: Sequelize.STRING,
unique: true
},
password: Sequelize.STRING
})
return User
}
thank you
OH MAN! I wish this used Firebase. I am having a hell of a time piecing together info from other tutorials into this.
Here: th-cam.com/video/0RoT17Xwj24/w-d-xo.html
I literally just finished this series as of 10 minute ago. Great find.
Thanks love the tutorial, has helped me a lot.
Estan geniales tus videos. wonderful
Exitos en tu proyectos, Dios te bendiga
I’m new to the whole full stack world, typically I just make programs with c, c#, Java, and I got a question. Is it normal to build web applications with so many dependencies? Just looking at your folder node-modules you have like 100 other dependencies.
i bet you already know what that is by now haha,we re not gonna include all them modules to `production build` except the ones we needed only
If anyone is unable to install sqlite, make sure you update node.js to the latest version
Thanks man for this great video
At 2:17 just so you know it's an @ symbol, not a 0! npm install --save sequelize sqlite3@3.1.8
Messed me up :)
Two errors I was getting:
1) async function 'unexpected identifier' ~ this was due to node being outdate. Upgrade following these directions: www.hostingadvice.com/how-to/update-node-js-latest-version/#linux
2) 'install sqlite3 manually' ~ this worked for me: github.com/mapbox/node-sqlite3#building-for-node-webkit
Thank you for these :)
At 25:00 you have both the Controller and Policy in the routes.js file. This file could grow fairly large, if you have lots of controllers and policies. Is there a better way to organize/refactor this? Maybe creating a separate file for each controller/policy pair, then including/requiring/importing them into the main routes.js file? Is this something you can show in the next part?
(node:5608) [ESLINT_LEGACY_OBJECT_REST_SPREAD] DeprecationWarning: The 'parserOptions.ecmaFeatures.experimentalObjectRestSpread' option is deprecated. Use 'parserOptions.ecmaVersion' instead. (found in "standard")
Amazing! Thanks =)
Cody could you please update this for 2023? Many thanks!
15:09, 30:40, 43:56
love your voice! :)
I was just thinking the same thing 0.o
For the validation, you display each message separately, depending on how many errors you have, but is there a way to return all errors at once and highlight the fields with errors? Is this something you can show in the next part?
I am having an error in which constraints stated in User.js file is not been applied on my input.
for Ex. Email should be unique, but it is even accepting duplicate emails. If anyone else also faced these errors kindly help.
Hey, nice video. Any reason you're using joi instead of sequelize for validation? Just curious.
Very helpful
Cody Seibert other tutorials I've seen seem to suggest (and I agree with this) that validation should occur at multiple stages. So you can validate through the database definition, in your controllers, and every step in between.
The reasons I've seen given for this are that a) a client you don't control might connect to your back end but catching errors close to the UI gives better UX and performance, and b) not all types of validating are available at all levels.
This is my first time using anything SQL based. I normally use MongoDB and I use Joi's validation along with Mongoose's validation. So if I decide to actually use this app or use it as an example for something else I will definitely use sequelize validation rules as well.
My register page wasn't centering with the given code, maybe the library changed? Either way I solved it by changing the v-layout tag to
ty so much dude, im really stupid so i couldn't even rename it by myself, it's fie with your help though, ty so much again :)
bro you are way to fast :D but thank you so much
its funny how the views drop from 200k to 30k for the remaining parts.
Hello, thanks for the course. I have a problem with sequelize.import() he don't work and the website says he is deprecated i replace it with require but nothing. And if he don't work, i can't create a user , he send me an error like "can't read property create of undefined" the "undefined" is the User model we use to create a user. Thnaks
I'm not sure if you've resolved the issue already but try this in case you're stuck: const model = require(path.join(__dirname, file))
@@kentarooka3459 thanks for the response i stopped the course because dealing with SQL databases is very hard.
mamadou yacine Gueye no worries maybe mongodb is easier to deal with
@@kentarooka3459 Yes i think or the course is little outdated
Query not executing for me at 14:28. Server has started normally. No sqlite file was created.
having the same issue - Any luck?
I had the same issue, I found that I was not returning the result of the filter condition. I was doing this:
fs
.readdirSync(__dirname)
.filter((file) => {
file !== 'index.js'
})
instead of:
fs
.readdirSync(__dirname)
.filter((file) =>
file !== 'index.js'
)
why there should be no brace?
Not putting the brace in arrow function means there is an implicit return,
so if you put the braces in the arrow function, you need to explicitly give the return statement.
So either this
fs
.readdirSync(__dirname)
.filter((file) => file !== 'index.js' )
or this
fs
.readdirSync(__dirname)
.filter((file) => {
return file !== 'index.js'
})
@@dogemaester You saved me! I couldn't find out why the table was not being created. Thanks very much!
Great set of videos!!
I am already quite a bit further through the videos than this part 2, creating the code along with the videos. But it occurred to me: I cannot figure out how the "updatedAt" and "createdAt" are being generated, for instance, at time 21:50. What library is automatically adding this to the payload? Is it getting added to the sqlite3 DB? We didn't add these columns to the database when creating the model.
Thanks!
Thanks for the quick reply! I didn't realize that was done automatically. Now I see it here: docs.sequelizejs.com/class/lib/model.js~Model.html#static-method-init
Again, great work!!
I am using MariaDB and I am getting this issue: throw new Error('Dialect needs to be explicitly supplied as of v4.0.0'); I tried a few things including adding dialect to my env in config.js but I am still stuck
great set of video, thankyou! i already have some difficulties to catch up the syntax e.g. double bracket: require('./route')(app) and variable with {} e.g. const {sequelize} and etc... where should I learn these? thankyou
require('./route') returns a function which takes an app. see www.tutorialsteacher.com/nodejs/nodejs-module-exports. You could do this and get a similar result
const f = require('./route')
f(app)
The reason for this is that in routes.js you say
module.exports = (app) => {
// stuff here
}
require('sequelize') returns an object which has a sequelize property. In js, if you get an object, you can deconstruct its properties into separate things by putting property names into {}. see exploringjs.com/es6/ch_destructuring.html. In this case we're just interested in the sequelize property. You could do this and get a similar result:
var s = require('sequelize')
var sequelize = s.sequelize
edit: * for bold didn't work so removed
@@JohnLudlow thanks! This helped a lot more than you know.
@@NeoNineOne :) glad I could help. I'm here to learn like anyone else but it's always nice if I can aid others in their own quest for more knowledge.
Hi, thanks for another great video. Is there a reason to use routes and controllers? I started working with express.Router so I just have my routes folder and in each file just the functions involved with the route. Is it just a coding style question or does this approach have advantages?
Thanks!
So far I'm amazed since the first part but on this 2nd part,
I can't install sqllite3. The few last lines of the debug log goes like
2416 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:288:5)
2417 verbose pkgid sqlite3@5.0.1
2418 verbose cwd D:\Web\Vue.js\Web Apps\tab_tracker\server
2419 verbose Windows_NT 10.0.18363
2420 verbose argv "C:\\Program Files\
odejs\
ode.exe" "C:\\Users\\User\\AppData\\Roaming\
pm\
ode_modules\
pm\\bin\
pm-cli.js" "install" "sqlite3"
2421 verbose node v14.15.5
2422 verbose npm v6.14.4
2423 error code ELIFECYCLE
2424 error errno 1
2425 error sqlite3@5.0.1 install: `node-pre-gyp install --fallback-to-build`
2425 error Exit status 1
2426 error Failed at the sqlite3@5.0.1 install script.
2426 error This is probably not a problem with npm. There is likely additional logging output above.
2427 verbose exit [ 1, true ]
why in Api.js you export default as Function ?
Hello, thx for this serie, really good job so far ! It's the first time I hear about sequelize, any reason why you prefer sequelize/sqlite over mongoose/mongodb ?
21:52 it is always returning a 400 status error
I am having the same issue, did you perchance happen to find a solution?
@@WesChege Ya, I did find the solution. But for me it was a specific code problem, in the index.js file in models, when we used the fs file system I accidentally put the code of the line 17 in {} braces, while returning file in the filter function :)
@@rishidusad2985 thanks mate, I have checked that but I don't think that's my problem though, when I call the register end-point I get this response error...
{
"name": "SequelizeDatabaseError",
"parent": {
"errno": 1,
"code": "SQLITE_ERROR",
"sql": "INSERT INTO `Users` (`id`,`email`,`password`,`createdAt`,`updatedAt`) VALUES (NULL,'test@test.com','test1234','2020-07-12 08:20:51.913 +00:00','2020-07-12 08:20:51.913 +00:00');"
},
"original": {
"errno": 1,
"code": "SQLITE_ERROR",
"sql": "INSERT INTO `Users` (`id`,`email`,`password`,`createdAt`,`updatedAt`) VALUES (NULL,'test@test.com','test1234','2020-07-12 08:20:51.913 +00:00','2020-07-12 08:20:51.913 +00:00');"
},
"sql": "INSERT INTO `Users` (`id`,`email`,`password`,`createdAt`,`updatedAt`) VALUES (NULL,'test@test.com','test1234','2020-07-12 08:20:51.913 +00:00','2020-07-12 08:20:51.913 +00:00');"
}
21:39 anyone else running into the issue where they always get the error returned?
Yeah same issue, did u find a solution?
in your filter((file) => { file !== 'index.js' })
don't use curly braces
At 21:35 in the video, I get a syntax error ---- /Users/ekeyur/tab-tracker/server/src/controllers/AuthenticationController.js:4
async register (req, res) {
^^^^^^^^
SyntaxError: Unexpected identifier
at Object.exports.runInThisContext (vm.js:76:16)
at Module._compile (module.js:542:28)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
Did anyone have this problem? Everything was working fine before this.
Same for me.
how did you fix this i am having the problem
I haven't been able to fix the problem.
Could it be that I don't have mySQL installed on my computer. Do you guys have it installed? I only have postGreSql
Hey guys, I got this and eventually worked out it was due to having an old version of node on my machine (7.4.0 I think). Fixed by going to console and typing 'nvm install 8.4.0' (latest version to date)...
update nodejs version and npm rebuild
What is the significance of brackets in {User} ?
Sequelize has the weirdest versioning system I ever saw. A year ago they were on 4.8 and now they are on 4.38 lol Seeing their version history made me very suspicious for using this package , among other things.
Almost everyone got errors, right?
Error: Please install sqlite3 package manually, how to solve this am using windows 10
npm install sqlite3
What is the full version of the sqlite you installed? It is not installing on my machine. I tried npm install sqlite3 --build-from-source to for compiling it after installing node-pre-gyp --fallback-to-build but it is still not working
Hey
I'm following your videos, but I'm having problems using Vuetify
At first it is working partially, when using cyan for example I am not getting the color. I am receiving a warning message regarding v-flex saying that the component failed to resolve.
I'm using vue3 and vuetify 3, I've tried everything and I can't get this thing to work correctly
What is the difference between Node's export default {} ,export default()=>{} and module.exports
I am a littel confused: What is serving the vue stuff? Usually I had in the backend a res.render("whatEver") which returns a view, but here, "npm run serve" serves the vue stuff, not express. Is that how this is run in production?
when doing validation I added two things I also allowed certain special characters and I told joi to look for two parts to the domain for the email. With out that someone could register with test@test and it would work. Now it requires test@test.com or .edu or whatever.
so here is what my email verification looks like...
email: Joi.string()
.email({
minDomainAtoms: 2
})
and here is what my password verification looks like...
password: Joi.string()
.regex(new RegExp(/^[-@./#&+\w\s]{8,30}$/))
.required()
Can I use mongodb in this tutorial session? instead of sqlite3?
I wish you showed us Mongo :(
Just found this tutorial and wondering if anyone has completed it recently? I want to learn more about connecting Vue & Node to SQL databases but I'm hesitant to start it because of the many issues related to changes in sqlite & sequelize. Have you guys been able to solve these issues? I'm pretty comfortable with Vue and Vuetify so not worried about changes from that end.
Hadn't encountered the syntax ```const {error, value} = Joi.validate({ a: 'a string' }, schema);``` specifically referring to the left side. Is this ES6 syntax or just a thing specific to Joi? Also, if it's an ES6 thing I'd love it if someone had a link to documentation so I can read more :D
Am I the only one having a problem with getting a unique email constraint working ?! I've been looking for a solution and I think its a sequelize issue and I have to add some code for it to work
queryInterface.addIndex()
Did anyone else had the same issue ?!
and about the error message, how can we change it dynamically so that it returns a message depends on the error
How can I define a URL prefix to each route like "api/v1" using this method?
Vuetify.min.css is not being recognized in my app. This is an issue I don't know how to fix. everything was working and looking fine, but now no styles are presented once this has been imported. Also nodemon doesn't work now. any solutions?
the v-flex is stratching until the right end for me, is there any way to fix it? it's defaulting for max-width 100%
i used row instead of column, not sure how it will affect things tho
Same issue. Row helped
nice
I thought joy is a library not a framework
My vuetify styling is all messed up. Did they change something that I am missing
yes mine too
@Anthony McGaw change it according to your code
This one works
How did you fix the styling? Im also having issues haha thanks men.
Is it safer to use this tutorial now as it is two years older? As there are a
lot of changes in vue and nodejs.
Its 95 percent is safe. Some modifications are necessary. The documentation is good for everything used
@@johnathaningle8855 thanks
ive been getting this error, pls can someone help out ,,,Cannot read property 'create' of undefined
I have the same issue. I found that at the index.js file should change .filter(file => { file !== 'index.js') } to .filter(file => file !== 'index.js'). Hope this help.
can't install Joi !
I am getting the error saying that This is related to npm not being able to find a file.
what can I do? any help plz?
You figure it out? I ran into this too.
npm un sqlite3
npm install --save sqlite3
npm install --save joi
That did it for me. I had pinned sqlite3 to version 3.1.8 like he did in the video which was the problem.
Thanks! this was very helpfull
Top answer! I had the same problem and this solved it.
I made a mistake while creating the User model and wrote eamil imstead of email which means that my table users has a column called eamil!
how can I alter the user table and change the column eamil to email?
I am just wondering what are 'db.sequelize = sequelize' and 'db.sequelize = Sequelize' for?
These add two new items to the db object which is what gets exported. db.sequelize = sequelize attaches the sequelize object we created in the file and db.Sequelize = Sequelize (make sure both have uppercase S, btw) attaches the Sequelize library which we import at the top of the file.
Thanks!
Hi, just started this great tutorial, but I stopped at 14:38. I am getting this error:
'Dialect needs to be explicitly supplied as of v4.0.0'
I tihnk this is due to update in packages. can someone help me?
in your index.js file add the dialect there ..see code below...
const sequelize = new Sequelize(
config.db.database,
config.db.user,
config.db.password, {
dialect: 'sqlite',
storage: './ProjectX.sqlite'
}
..the error says that u need to explicitly write that
const sequelize = new Sequelize(
config.db.database,
config.db.user,
config.db.password, {
dialect: 'sqlite'
},
config.db.options
)
@@mharrvic still don't works
How to deal with associations like belongsTo in the way models are imported in this code ? I added a prototype method to the models called "defineAssociationsUsingModels" that I call on each model with another forEach. What do you think ?
Ok I saw it is covered in the tutorial, part 6 at 38:07.
why you write const {sequelize} and not const sequelize??
At 15:53 I have an error tab-tracker\server\src\models\index.js:8
database: config.db.database,
^
TypeError: Cannot read property 'database' of undefined
why my color doesnt work ?
Im also having this error. Did you manage to fix it?
I want add name, last name and pass conf ..what i need to change here?
Error: Dialect needs to be explicitly supplied as of v4.0.0
at new Sequelize
help me guys
Great tutorial!!!... I just have a question, what if instead of using vuetify I want to use custom and different css and js external files for every file.vue? does anybody know whats the best approach to achieve this? Thanx!!!
To add css to a specific component try the following:
your css goes here
You can put this at the bottom of your file and styling will only apply to the component where the css lives. Don't think you need external js files, you should be able to put your js inside of tags when you build your "controller".
Great video here, but i am having problem installing joi.. giving me error and after the error, it crashes the server. so i have to re install sqlite and the server will work again. please how can i solve the joi not install.
i've the same issue, and then i install sqlite3 to 3.1.13, then i'm able to install joi
Hello! I always get "error": "This email account is already in use!". How to solve this problem?
Hey! I´m also having the same issue. Could you fix it?
@@carolinalaborde8282, actually not. I don't have any idea about why this error comes
@@carolinalaborde8282 if you will find the solution, please tell me. With this problem, I can't continue this course.
were you even able to get it to create your database table?
I just found this tutorial and was thinking of going through it to learn more about connecting Vue & Node to SQL. I'm hesitant to because of the many issues related to changes in sqlite/sequalize. Have you guys been able to solve these issues? I'm pretty comfortable with Vue and Vuetify so no worried about changes from that end.
I'm getting SequelizeConnectionRefusedError. I'm trying to use Postgres. Do i need to install postgres and start the server?
of course! sqlite and postgres are two different db's
Executing (default): INSERT INTO `Logins` (`id`,`createdAt`,`updatedAt`) VALUES (DEFAULT,'2018-09-27 21:54:13','2018-09-27 21:54:13'); why error ?
"TypeError: sequelize.sync is not a function" can anyone help me with this?
Allen Josh Misenas lol, I’m having same issue with sequelize.import
@@ИванЖуравлёв-у5т replace that line with this: const model = require(path.join(__dirname,file))(sequelize, Sequelize.DataTypes), worked for me
I am getting this error after setting up User.js and Index.js (Error: Please install sqlite3 package manually). I tried reinstalling all my npm modules. I double checked and it's saved in my package.json. I also tried using different versions of sqlite3. To no avail.
I ended up just using postgresql instead. Worked on first try and had to change minimal code. Great tutorial. This is exactly what I was looking for while on my way towards full stack development.
how is his try catch working on an asynchronous environment? gawd
Seems unusual, I know, so I looked it up: "One of the goals of async/await is to make asynchronous code appear more syntactically similar to synchronous code. This is also true for error handling." www.syntaxsuccess.com/viewarticle/async-await-error-handling
Hello guys,,, has anyone experience this error -TypeError: sequelize.sync is not a function - with sequelize.sync function? ,.,, i've been stuck on it for the past three days and lastly have resorted to copying the app code from the Github repo and still would not compile cleanly.... any idea? thanks
Hello. I'm struggling to find out which part of script creates tabtracker.sqlite database? I deleted my db file and wonder how it has to be created. Appreciate if somebody can help!
I'm having problems in the app.js it returns:
"TypeError: sequelize.sync is not a function"
can anyone help me with this?
Which coding software is being used here?
Visual Studio Code
VS Code
Anybody get the issue where it lets you add multiple of the same email?