Contents hide 1) The app folder 2) The Main App File 3) The Gulp File 4) The models Folder 5) The Controller Folder 6) The Middleware Folder Download Node App Structure Download Node Download Version Control The app folderDownload & install Node Server & Git-version controll.letβs start with building the app. As for Node Express App first, download the required things. Create a folder contains the node express app structured files. Open up the git version control (terminal), then go to your current directory of your app and install node packages through command.$ npm installThe Main App FileThe core file from where the app starts its execution. This files connect the whole folder structure i.e model, controller, middleware etc.app.jsvar express = require('express'); var app = express(); var bodyParser = require('body-parser'); var session = require('express-session'); var fs = require('fs'); var morgan = require('morgan'); var db = require('./models/db.js'); var router = express.Router(); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: true })); if(GLOBAL.SQLpool === undefined){ GLOBAL.SQLpool = db.createPool(); //create a global sql pool connection } app.use(session({ secret: 'keyboard cat', resave: false, saveUninitialized: true })); morgan.token('res', function getId(res) { return res; }); var accessLogStream = fs.createWriteStream(__dirname + '/logs/access.log', {flags: 'a'}); app.use(morgan(':req[body] :res[body]', {stream: accessLogStream})); app.use(require('./controllers')); app.use('/', express.static(__dirname + '/client')); app.use('/bower_components', express.static(__dirname + '/bower_components')); app.listen('3000', function(){ console.log("Connected on port 3000."); });The app.js file contain the node express models package (inbuild packages).The Gulp FileInstall Gulp Globally$ npm install gulp -gThe gulp file make the app to run on localhost on port localhost:3000. To start the server go to the file directory in terminal and just enter gulp$ gulp gulpfile.jsvar gulp = require( 'gulp' ), server = require( 'gulp-develop-server' ) jshint = require('gulp-jshint'); gulp.task('lint', function() { return gulp.src('app.js') .pipe(jshint()) .pipe(jshint.reporter('default')); }); // run server gulp.task( 'server:start', function() { server.listen( { path: './app.js' } ); }); // restart server if app.js changed gulp.task( 'server:restart', function() { gulp.watch( [ './app.js', './controllers/**/*', './models/**/*', './middlewares/**/*' ], server.restart ); }); gulp.task('default', ['lint','server:start','server:restart']);The models FolderThe Models Folder contains the database connection code in db.js And also contain th querie related to the application in module wise. Each module of the application is seperated whith there query. The Controller FolderThe Controller folder contains the API for the application such as products users. The Middleware FolderThe Middleware folder contains the authentication part for the application. example Permission for the following users etc.Demo : Folder StructureRelatedTags: JavaScript, nodejs