Giter Club home page Giter Club logo

sssk's Introduction

A super simple starter kit for Node.js

There is no one way to structure your Node.js application files, but throwing everything into a single server.js is not an acceptable option. Take a look at this simple application structure, do your best to understand it, and apply it in your projects.

server.js

Call this what you like: app.js, index.js, server.js or whatever. Anyway, it should include references to only two packages: http and your router package.

router.js

You do not have to have a router, but it helps. This is the package that acts as the traffic cop in your application, mapping incoming requests to appropriate application responses. The router should reference only a single package: handlers.js.

handlers.js

The handlers are where the behaviour of your application is defined and where most of the work in your application is likely to be done. In a simple application like this one, all the handlers can go in a single file; in complex applications, the main handler may reference several different files. Unlike the main server file and the router, the handlers are going to need access to your data model.

model.js

The data model is not just the file where you put all your database connexions, but also where you define how you can access that data and what the data should look like. If any assumptions about your database leak into your handlers, something has gone wrong. You should be able to completely change the database you are using and it have no efffect on the rest of your application. Concerns should be kept separate between data and presentation.

test/test.js

Don't forget to add the appropriate test script to package.json. As an exercise, create some passing tests for this application.

sssk's People

Contributors

sofer avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.