Reputation: 1
I am a new StackOverflow user and I am starting to learn the back-end side of programming.
I use mostly JS client-side so the back-end side has some things that I need to clarify.
I have a problem regarding Node and its connection with the browser, even using browserify.
I know that a browser isn't Node's environment but I need to use that because I need to learn the little details of it.
The problem is, even though I use browserify in order to bound the several npm modules, everytime I try to require MySQL or HTTP or Express, errors occur.
If I use require('http') and/or require('express') this error occurs: TypeError: http.ServerResponse is undefined;
If, instead, I use require('mysql') this error occurs: TypeError: Net.createConnection is not a function
My questions are:
-How can I solve this?
-Those are errors relative to browserify or they would be the same without it, using an environment different from the browser?
I'll prefer not a straightforward solution but an explanation with the code if necessary.
Thank you very much in advance
Upvotes: 0
Views: 93
Reputation: 360
Modules such as mysql
need low-level network interface. http
is an abstraction over that network interface. So you really need net
module, which is not avaliable in browser environment at all.
Browserify is just a semi-nodejs envirionment. It mocks up some of modules it can polyfill in browser.
You should install Node.js run your programm as such
node your_script.js
Upvotes: 1