Node js without framework, check code

Asked

Viewed 94 times

0

I’m trying to work with nodejs without framework to get a more detailed idea of how Node works.

This code is the following: I make a request in the database and pass the result to renderFile to send the object to the page, and so be able to style the page with the data from the database.

There’s something wrong with that code?

It is a wrong way to go down this path without using any framework?

function onFunction(req,res){
    con.query('SELECT * FROM barbeiro', function(err,result,fields){
        ejs.renderFile('./index.ejs',{data: result},(err,html) => {
            res.writeHead(200, {'Content-type':'text/html'});
            res.write(html);
            res.end();
        });
    });
}
  • No, it is not wrong to follow this path, today many pseudo-developers (and I include myself in certain cases) go straight to a framework, before mastering the tool, in your case the nodejs is the tool, and an Angular, Ember, Vue, React would be the framework

  • I’m studying Ode and I’m a little suspicious of everything I’ve been doing. I’ve used the Express and it works great, I just don’t feel like not understanding what happens underneath.

  • A personal tip, learn the basics of js, the paradigms available through the language, take some libs that are available in npm and add in your project to play, read about typescript and ecmascript 6|7|8 and only then go to a more consolidated framework.... The way to master js and Node today is quite long, if starting with a direct framework can hit your head a lot.

  • I had a problem understanding how a callback worked, I didn’t understand how sending a function brought me req and res, until I saw a video on youtube that showed how to apply a callback. One more question, you spoke with paradigm, worth programming javascript with oo?

  • I found no gross error in the code. I do not believe it is a wrong way to study, including I point out to all developers to try to develop some application of studies without framework, why you can better understand the functioning of Node.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.