0

I'm really confused. I started learning to use node.js with MEAN stack. Before I used webpack and browserfy without really understanding it.

What confuses me is the following:

  • Express fires up a server and I can handle the requests
  • Webpack fires up a server
  • Browserify fires up a server
  • simply typing in plain js e.g. var http = require('http'); http.createServer(function (req, res) { ... fires up a server

Well, Webpack and Browserfy (as far as I understand) also bundle js files. How does the logic "under the hood" works and do they bundle everything I code and send it to the client (E.g. my DB login)?

I read this one Webpack vs webpack-dev-server vs webpack-dev-middleware vs webpack-hot-middleware vs etc , which told me webpack uses express under the hood. So maybe express also uses the plan .js server under the hood?

Well, I can go on like this forever. I am a little confused.

Well, what and where are the differences and how do thee apps work (together)?

kn1g
  • 358
  • 3
  • 16

1 Answers1

2

First of all express use the core API and module of node.js like http module .

express uses the http module to create the server at specific port so

app.listen(3000);

will simple be like this

var http = require('http);
var server = http.createServer() ;
server.listen(3000) ; 
server.on('request',function(req,res){
  // here express will do all its magic 
  // and handle the request and response for you under the hood 
})

Second things is that webpack and other bundling tools is used for bundling files and assets in the front end not the back end and they can create simple server for listening for changes in your files to give you other features like + live reload + hot module replacement but also you can use webpack in the back end to use things like babel-loader or use the hot module replacement feature

so express works for the back end and webpack use it in the front end

you can create different ports on each server and communicate between them via ajax API like fetch and that's how actually it should work .

learn more understanding express.js

understanding express and node fundamentals

webpack.js concepts and documentation

mostafa tourad
  • 4,308
  • 1
  • 12
  • 21