vikram vikram - 1 year ago 130
Node.js Question

Can I use node.js server modules in webpack?

Can we import all

modules in webpack and create a
? Example what if I use
module and webpack application and bundle it and run in browser?


var http = require('http');
var server = http.createServer(function (req, res) {
// send output

Answer Source

When using Node's built-in libraries with Webpack, it will automatically import a browser-compatible version when available.

You can see the entire list and matching packages in this file.

For http, you'll end up with http-browserify instead. Not everything is supported, so creating a HTTP server will not work (as this isn't possible in a browser). You can still use http to do requests as shown in the documentation.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download