Reputation: 323
Consider I have been done with my NodeJs with Express and MongoDB Application. I can bundle up my application to deliver the same to client but in that case client have to install all required npm modules and change mongoDB connection url. So to counter this issue:
Is there any other way to bundle my application so client do not need to install any npm modules to run application? If yes, then how client can connect to his mongodb?
Upvotes: 15
Views: 30715
Reputation: 5380
You can use good old webpack
by setting it's target to node
. here is a simple webpack.config.js
:
import webpack from 'webpack';
export default {
entry: "./server.js",
output: {
// output bundle will be in `dist/buit.js`
filename: `built.js`,
},
target: 'node',
mode: 'production',
// optional: bundle everything into 1 file
plugins: [
new webpack.optimize.LimitChunkCountPlugin({
maxChunks: 1
})
],
};
Upvotes: 2
Reputation: 670
pkg by Vercel works really well for me. It bundles everything into a single executable that runs out of a terminal. This makes it really easy to distribute.
To connect to a Mongo instance, you would have to have some kind of configuration file that the user edits. I recommend putting into the user data folder (Application Support on Mac and AppData on Windows), but you could have it sit right next to the packaged executable.
Upvotes: 16