File structure for a Nodejs app with webpack

Hello,
so I started learning webpack, and I am wandering, how should I structure my Nodejs web app?
and I would like to add Webpack to my already existing project.
this is the file structure,

_ node_modules
_ src
       |_ config
       |_ models
       |_ public
       |_ routes
       |_ views
_.env
_.gitignore
_package-lock.json
_package.json
_server.js
_wepack.config.js

how should I re organize my file structure, and should i bundle the routes/models/config/server.js files?

if not then how can i tell webpack to skip them?

Why do you feel you need Webpack if you’re building a Node app? It generally has nothing to do with Node apps, it’s specifically for frontend development to deal with the fact that you normally need to compile code written in modules down to something the browser can deal with

1 Like

oh ok then, I should separate my public front-end files from the back-end files. I would like to be able to use the module.exports to modularize my code on the front-end since it has a lot of repeated code,
and to be able to test them with jest.

Ah, so normally I would say in the folder for the client stuff have another package.json (and then all the frontend stuff gets installed in its own node modules folder), all the frontend config stuff in there, as generally it doesn’t have anything to do with the backend. But there’s no set structure I’m afraid (other languages/frameworks say file A must go here, file B must go there, JS/Node/etc doesn’t, which is a pain in the ass tbh). You could just install everything in the root or not, best advice I can give is look at a whole load of guides on setting up a project and see which one makes most logical sense to you.

Jest can be used for the whole project, and you can tell it to use a config file when you run it, which means you can have one config file for the Node serverside stuff, one for the frontend stuff

1 Like

Thank you for your help, I will look up the guids, if you know a good one, that would help a lot.
thank you so much.:heart: