So far I've always been developing my clientside applications without any of my own servers running behind it, using Webstorm's built-in webserver to serve my content.
What I frequently see when people use Node with Express to act as their webserver is the debate on if you should put your html files with node or with the client code.
So my first question is, with a folder structure like this
app/ client/ js files server/ node files
Should you include your html pages in your server or your client directory?
Sometimes I see people use
As far as I can see, the only advantage I have with using Node instead of the built-in webserver is if I want to have database access.Answer1:
The files for your pages themselves are still static. That is, you are not creating them dynamically with server-side code. What happens in the browser doesn't matter in this context... the idea is that you do not need to generate these files on the fly, as their content does not change.<blockquote>
Where you store your files on the server doesn't matter. What does matter is that you don't generally want to serve static files from your Node.js application. Tools like
express.static are for convenience only. Sometimes, you may have a low traffic application. In these cases, it is perfectly acceptable to serve files with your Node.js app. For anything with a decent traffic load, it's best to leave static serving up to a real web server such as Nginx, since these servers are far more efficient than your Node.js application.
You should keep your application code (code that serves dynamic responses, such as an API server) within your Node.js application.
It's also a good idea to put your Node.js application behind a proxy like Nginx so that the proxy can handle all of the client interaction (such as spoon-feeding slow clients) leaving your Node.js application to do what it does best. Again though, in low traffic situations it doesn't matter.Answer2:
Sometimes I see people use express.static for static files, what exactly is implied by static files here?</blockquote>
I believe you're referring to this bit of code usually found an an express app's
express.static() is a bit of middleware that maps directory names to the path directory for easy lookup. Usually you'll have:
If you have a script in your
Static files are best considered as files that are not include by something like NPM or Bower. They are your own scripts, stylesheets, images, etc. It has nothing to do with the page being dynamic or static.
As to your first question:
Im personally not sure of the need for that kind of project architecture if you're using node. If you're using node and something like <a href="http://emberjs.com/" rel="nofollow">Ember.js</a> or <a href="https://angularjs.org/" rel="nofollow">Angular</a> for your clientside app, than I would personally put my actual application scripts inside of the
At the end of the day, pick a project structure you like, and stick with it. If other people are working on the project however, stick with common conventions. It makes life easier.