B
B
bumbay2014-09-02 16:56:19
Node.js
bumbay, 2014-09-02 16:56:19

How to create the structure of a Node.JS application?

Hello.
Task: to write a site (chat) on node.js + socket.io, mongodb and angularjs.
What will work and how?

- node will only be used to return index.html and process ajax requests
- nginx will return all statics to the node server
- angular will navigate through pages and load data from node via ajax

node.js will handle requests like this:
- registration and authorization
- saving and sending messages
- creating chats
- loading chats
- and many small functions that will work with mongodb through node

node will only give responses in json format and sometimes accept files (you can say api)
There will be about 3-5 mongoose Schema models
- chats
- users
- messages
- other..
..

There will be about 20-30 post processors that will be linked to mongodb.
Now there is a small prototype. Works using express.
There, all the code except for models and some libs lies at the root, in server.js - I don't like it, because I feel that this is not correct.
code - processing ajax post requests, the rest is a trifle (connecting modules and starting the server)

What I want?
- so that knowledgeable and experienced programmers can tell you how to properly organize work with models and process ajax post requests?
- I want to know how not to do all this in one file?
- or maybe do?
I thank everyone who tries to help me.
Sincerely.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
K
Konstantin Kitmanov, 2014-09-02
@k12th

sudo npm install -g [email protected]; mean init myApp

A
Alexey Yaroshevich, 2014-09-11
@qfox

It is better to wrap models in abstraction, moreover, take out the general code separately, the code for the browser - separately, the code for the node - separately. To make `require(['fs'], (fs) => fs.read)`, for example, work the same in the browser and in the node.
Do not do it in one file - scatter it among plugins, look / try the architect and pym packages, or use your own interface. It is even better to use some kind of cluster and do all the functionality of the application in one thread. Many small ones are better than one big one.

S
scapp, 2015-06-05
@scapp

sails generate new coolMongooseApp

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question