Getting started with Node.jsnpmWeb Apps With ExpressFilesystem I/OExporting and Consuming ModulesExporting and Importing Module in node.jsInstalling Node.jsMySQL integrationReadlinepackage.jsonEvent EmittersAutoreload on changesEnvironmentCallback to PromiseExecuting files or commands with Child ProcessesCluster ModuleException handlingKeep a node application constantly runningUninstalling Node.jsnvm - Node Version ManagerhttpUsing StreamsDeploying Node.js applications in productionSecuring Node.js applicationsMongoose Libraryasync.jsFile uploadSocket.io communicationMongodb integrationHandling POST request in Node.jsSimple REST based CRUD APITemplate frameworksNode.js Architecture & Inner WorkingsDebugging Node.js applicationNode server without frameworkNode.JS with ES6Interacting with ConsoleCassandra IntegrationCreating API's with Node.jsGraceful ShutdownUsing IISNode to host Node.js Web Apps in IISCLINodeJS FrameworksgruntUsing WebSocket's with Node.JSmetalsmithParsing command line argumentsClient-server communicationNode.js Design FundamentalConnect to MongodbPerformance challengesSend Web NotificationRemote Debugging in Node.JSMysql Connection PoolDatabase (MongoDB with Mongoose)Good coding styleRestful API Design: Best PracticesDeliver HTML or any other sort of fileTCP SocketsHackBluebird PromisesAsync/AwaitKoa Framework v2Unit testing frameworksECMAScript 2015 (ES6) with Node.jsRouting ajax requests with Express.JSSending a file stream to clientNodeJS with RedisUsing Browserfiy to resolve 'required' error with browsersNode.JS and MongoDB.Passport integrationDependency InjectionNodeJS Beginner GuideUse Cases of Node.jsSequelize.jsPostgreSQL integrationHow modules are loadedNode.js with OracleSynchronous vs Asynchronous programming in nodejsNode.js Error ManagementNode.js v6 New Features and ImprovementEventloopNodejs Historypassport.jsAsynchronous programmingNode.js code for STDIN and STDOUT without using any libraryMongoDB Integration for Node.js/Express.jsLodashcsv parser in node jsLoopback - REST Based connectorRunning node.js as a serviceNode.js with CORSGetting started with Nodes profilingNode.js PerformanceYarn Package ManagerOAuth 2.0Node JS LocalizationDeploying Node.js application without downtime.Node.js (express.js) with angular.js Sample codeNodeJs RoutingCreating a Node.js Library that Supports Both Promises and Error-First CallbacksMSSQL IntergrationProject StructureAvoid callback hellArduino communication with nodeJsN-APIMultithreadingWindows authentication under node.jsRequire()Route-Controller-Service structure for ExpressJSPush notifications

Project Structure

Other topics

Remarks:

The project above uses browserify and vue.js modules as application base view and minification libs. So the project structure may changes minutely based on which mvc framework you use e.g. The build directory in public will need to contain all the mvc code. You can have a task which does this for you .

A simple nodejs application with MVC and API

  • The first major distinction is between the dynamically generated directories which will be used for hosting and source directories.
  • The source directories will have a config file or folder depending on the amount of configuration you may have . This includes the environment configuration and business logic configuration which you may choose to put inside config directory.
 |-- Config
        |-- config.json
        |-- appConfig
            |-- pets.config
            |-- payment.config
  • Now the most vital directories where we distinguish between the server side/backend and the frontend modules . The 2 directories server and webapp represent the backend and frontend respectively which we can choose to put inside a source directory viz. src.

    You can go with different names as per personal choice for server or webapp depending on what makes sense for you. Make sure you dont want to make it too long or to complex as it is in the end internal project structure.

  • Inside the server directory you can have the controller ,the App.js/index.js which will be you main nodejs file and start point .The server dir. can also have the dto dir which holds all the data transfer objects which will be usd by API controllers.

     |-- server
          |-- dto
              |-- pet.js
              |-- payment.js
          |-- controller
              |-- PetsController.js
              |-- PaymentController.js
          |-- App.js
    
  • The webapp directory can be divided into two major parts public and mvc , this is again influenced by what build strategy you want to use. We are using browserfiy the build the MVC part of webapp and minimize the contents from mvc directory simply put.

    |-- webapp |-- public |-- mvc

  • Now the public directory can contain all the static resources,images,css(you can have saas files as well) and most importantly the HTML files .

|-- public 
    |-- build  // will contianed minified scripts(mvc)
    |-- images
        |-- mouse.jpg
        |-- cat.jpg
    |-- styles
        |-- style.css
    |-- views
        |-- petStore.html
        |-- paymentGateway.html
        |-- header.html
        |-- footer.html
    |-- index.html
  • The mvc directory will contain the front-end logic including the models,the view controllers and any other utils modules you may need as part of UI. Also the index.js or shell.js whichever may suite you is part of this directory as well.

     |-- mvc
         |-- controllers
             |-- Dashborad.js
             |-- Help.js
             |-- Login.js
         |-- utils
         |-- index.js
    

So in conclusion the entire project structure will look like below.And a simple build task like gulp browserify will minify the mvc scripts and publish in public directory. We can then provide this public directory as static resource via express.use(satic('public' )) api.

    |-- node_modules
    |-- src
        |-- server
            |-- controller
            |-- App.js   // node app
        |-- webapp
            |-- public
                |-- styles
                |-- images
                |-- index.html
            |-- mvc
                |-- controller
                |-- shell.js  // mvc shell
    |-- config
    |-- Readme.md
    |-- .gitignore
    |-- package.json

Contributors

Topic Id: 9935

Example Ids: 30554

This site is not affiliated with any of the contributors.