Thursday 21 March 2019

[Question] How to use node modules in different situations ? (mainly in the web)

So recently I have been getting into programming with es6 and nodejs, but I have been getting confused with how to use node modules and could not really find a source that answers my questions.I understand that if you have a local js file on your computer than you can simply install a module with npm install and then use a require statement. However, I also have seen that require is not supported in browsers.I have spent a lot of time researching and trying to figure out how people use npm and node in the browsers.using express js to have a front end and a backend that are linked togetherBrowserify to bundle all of your modules together and then load the bundled js file into your main html file.Basically I guess I don't understand how to use npm modules once the web is involved.Then there are cases where a web specific framework is supposed to be installed using npm, but then I don't know how to require it. Or if I use browserify to load the module in it has no access to the backend and server side.I have also heard about other services such as Commonjs, requirejs, webpack, etc.I'm just not really sure when to use what and was hoping someone would be able to give me a better explanation or point me to a resource to help me out.I think a good example of something I was trying to do once was use the fs module to read a json file and then display the parsed data to my webpage, but I didn't know how to link the backend and front end.edit: added an example

Submitted March 21, 2019 at 04:50PM by vin42tau

No comments:

Post a Comment