Eu estava fazendo uma video aula e segui os exatos mesmos passos do professor, porém esta dando o seguinte erro quando executo o codigo no powershell
Ate antes de começar a introduzir o sqlite tava rodando normal
"(node:4224) UnhandledPromiseRejectionWarning: Error: sqlite: filename is not defined
...
(Use node --trace-warnings ...
to show where the warning was created)
(node:10724) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either 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)
(node: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...')
}
})