How to Use Classes in Node.js

preview_player
Показать описание


How to Follow Along
2. Open a terminal and type: mongod
3. Open another terminal and type: npm install
4. convert server_old into classes

Find out how to use the class keyword in javascript as syntactic sugar to existing applications.
Рекомендации по теме
Комментарии
Автор

You've missed the point of classes, they're not just syntactic sugar if your implementing object orientated programming.

As a quick example you could have *decoupled* the Server class from it's reliance on Mongoose or needing to know the connection string by setting those when you initialise the class. Then it can be used with other mongo databases or even a different database provider.

XibaXela
Автор

cool tutorial, how would you encapsulate the server class into a separate module?

thomastaylor
Автор

Is useful using classes in node ? I have never seen anyone use classes in javascript

crl
Автор

With all due respect I think this is totally wrong. No separation of concerns nor encapsulation is achieved. You basically just "moved" code. To begin with, your "constructor" modifies external values that just "happen" to be in the same scope as itself. Also, the whole design implies that you could basically just have used mere functions instead of classes and achieved the same end result.

linuxdeveloperuy
Автор

dude I hope you familiarized a bit with some common "tab styled" code

aspirinemaga
Автор

This was extremely useful and thank you very much. Perfect explanations. Ive been looking at using latest morgan and it is strict on multiple instances of the same mongoDB connection, I havent been able to get my head around using the same instance of db con, or using it with another db connection when it comes to mongoose-morgan. There are no clear explanations on how to either use the same instance of DB connection and using a different DB with another instance. If you could do a tutorial on that, that would be absolutely awesome, since this one is so dope and very useful indeed.

djsargex