Friday 9 February 2018

Hi, i'm kinda new to node, and would like some insights

Ok, so i have a few questions, and this, seems the right place to do so:1)Let's say i have a structure like this:| --\libs ----\firstlib ------\node_modules ----\secondlib ------\node_modules myfile.js What would be the best way to load my modules? I've tried withrequire("./firstlib/node_modules/mymodule") require("./secondlib/node_modules/othermodule") which is ok, but i would like that, in myfile.js i could just do require("thelibineed"), and in package.json you can set only a {main: "***"} entrypoint. So, i would have to make just a libs.js file with require()?2)What's the best way to make classes and export them? Coming from a C++ background, i like to keep my code organized, but in node it becomes easily messy, knowing that it's not compiled, optimizing it seems tedious. Suppose i have to make a class module.exports = class aClass{ } How would i go about loading it? Because: const loadClass = require("./classes"); var niceClass = new loadClass(); Seems like wasting memory, with multiple requires i would have to make a lot of variables!3)What about deployment?I couldn't find a right place to seek, but i develop on Windows and deploy on Linux, so how would i go about importing my project? Do i need to place a package.json and just do npm install? I have 2 third-party modules that i need, is the package.json created in the directory automatically updated?

Submitted February 09, 2018 at 12:51PM by AnonymousAlien11

No comments:

Post a Comment