i think code will be return successfull before applisten but it's not work like i thought. i don't understan how does it work?
can sb explain why?
sequelize
.sync()
.then(() => {
console.log('successfull')
})
.catch(err => {console.error('err',err)});
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.use('/',loginRouter);
app.use('/admin',login);
app.use('/admin', indexRouter);
app.listen(3001,()=>{console.log('App running at http://localhost:3001');
})
App running at http://localhost:3001
Executing (default): CREATE TABLE IF NOT EXISTS `users` (`id` INTEGER NOT NULL auto_increment , `username` VARCHAR(255) NOT NULL, `password` VARCHAR(255) NOT NULL, `createdAt` DATETIME NOT NULL, `updatedAt` DATETIME NOT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB;
Executing (default): SHOW INDEX FROM `users`
successfull
This is an event loop problem in js, can be so simple to understand, then () returns the promise belongs to asynchronous tasks, app. Listen () is a sync task, and with js execution mechanism is first synchronization tasks to perform asynchronous task, please visit https://javascript.info/event-loop for more information
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With