Could you explain how the files flow in node js with express? For example, the application starts with app.js and then it goes to the routes' index.js file etc. In this flow where to add the business logic and how everything connects?
Node.js is a server side java script language. Express is node.js web application framework.
A basic directory structure for a project could look like this.
- app/ // application content
----- index.html
- node_modules/ // created by npm. holds our dependencies/packages
- package.json // define all our node app and dependencies
- server.js // entry point for application
You'll generally serve some type of index.html file as entry point for your application (declared in your server.js file). You will also have other routes defined in the server.js file that implement business logic or serve other content.
For instance if I was currently navigating to index.html (the default route '/') and clicked a button that is supposed to retrieve some data from the back end, I would implement something in the front end (AJAX call, Angular) to call my backend server functionality. My backend functionality would then go and process my request and send a response back to the front end.
The following is a very basic example of how you "glue" the front and back end together.
Backend:
app = express();
app.get('/getData',function(res,req){
/... code to get the data .../
});
Front-end:
$http.get('http://localhost:8080/getData').success(function(data){
/... do what needs to be done at the front end to display data .../
});