node.js - Understanding Proper Structure of a Node Application -


i'm trying figure out how best architect app. starters trying understand typical practices respect put things, , how app should wire things server.js, how server.js should work, , how keep persistent connection open website, , backend services or modules.

this general question let me try more specific, specific can since new node.. , basis start on question.

lets plan on designing simple express app.

i've got kind of structure example far:

enter image description here

right in server.js, playing around trying connect mysql database. i've got connection pool i'm creating, 1 call store retrieve data, requires @ time node-mysql middleware i'm using, etc.

app.js has simple code, it's not modular yet, or production ready that's me playing code, spiking things out. in have you're typical stuff setting view, var app = express();, importing express route definition module in routes\index.js, stuff that.

if i'm going keep database connection open, or other things open, how best organized/done convention?

if @ example code, he's moving var app = express() definition service.js: https://github.com/madhums/node-express-mongoose-demo/blob/master/server.js. keeps open connection running , started there, makes sense, hence "server".

so should app.js much? best practice or scope of should doing. once start modularizing things out own .js files , node modules, how app.js morph through refactorings, meaning in end what's role , thin in end it's used wire stuff up?

then should www.js required express 4 have , it's role?

it's kinda hard me start 1 aspect i'm kinda going on place here in above. want know common conventions putting stuff in app.js vs. server.js , best way keep , managed open connections things...both in backend , front-end such http requests coming in, should central point? routes of course app.js responsible referencing routes?

i have found few resources such this looking more if know or have input, please reply. i'm more interested in talk around app.js, server.js, connections, www.js, , things should wire each other these particular specific parts. realize rest on how wanna name folders, etc.

there no right way , (arguably) no wrong way. there better others, might don't way , should other way , on, until project on deadline.

i refer this blog post best practices when developing express app.

you try 1 of yeoman generators. choose 1 suits most/all of needs.

bottom line, there sadly still no answer best structure of app, recommend pick works best (and team) , stick it. consistency important thing keep in mind while developing , javascript community lacking it.


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -