-1
I was making a video lesson and followed the exact same steps of the teacher, but this giving the following error when I execute the code in the powershell
Even before you start entering the sqlite was running normal
"(Ode:4224) Unhandledpromiserejectionwarning: Error: sqlite: filename is not defined
...
(Use node --trace-warnings ...
to show Where the Warning was created)
(Ode:10724) Unhandledpromiserejectionwarning: Unhandled Promise rejection. This error either originated by Throwing Inside of an async Function without a catch block, or by rejecting a Promise which was not handled with . (catch). To terminate the Node process on unhandled Promise rejection, use the CLI flag --unhandled-rejections=strict
(see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(Ode:10724) [DEP0018] Deprecationwarning: Unhandled Promise rejections are deprecated. In the Future, Promise rejections that are not handled will terminate the Node.js process with a non-zero Exit code."
const express = require('express') /* para importar o express */
const app = express()
const sqlite = require('sqlite')
let db = new sqlite.Database(':memory:', (err) => {
if (err) {
return console.error(err.message);
}
console.log('Connected to the in-memory SQlite database.');
});
const dbConnection = sqlite.open('banco.sqlite', { Promise })
app.set('view engine', 'ejs') //seta parametros para olhar na pasta view, e procurar arquivos .ejs
app.use(express.static('public'))
/*apos verificar um pedido (chamar o /) na porta 3000 o app pega com o .get o request
e responde o response enviando a mensagem */
app.get('/', (request, response) => { /* pega as insformações do app */
response.render('home' ) // renderiza o arquivo home.ejs
})
app.get('/vaga', (request, response) => {
response.render('vaga')
})
const init = async () => {
const db = await dbConnection
await db.run('create table if not exists categorias (id INTEGER PRIMARY KEY, categoria TEXT')
}
init()
/* o app fica escutando a porta 3000 */
app.listen(3000, (err) => {
if(err){
console.log('Não foi possivel inciar o servidor do Jobify.')
}else{
console.log('Servidor rodando...')
}
})