Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Applisten run before sequelize?

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
like image 885
thiên nguyễn Avatar asked Jul 04 '26 19:07

thiên nguyễn


1 Answers

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

like image 105
小前端__Mr陈 Avatar answered Jul 06 '26 09:07

小前端__Mr陈



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!