0

Can we import all node.js modules in webpack and create a bundle.js? Example what if I use http module and webpack application and bundle it and run in browser?

main.js

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

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks , i got it, but it does not give any error during building process, i got error in browser, that's why think thought that why this happening :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.