Optimal approach for organizing code in Sails.js (Node.js) applications

In my application, I have different parts such as Public API, Admin API, Admin Console (GUI), Private API, and Auth API (oauth2, local, socials). Although these components are distinct from each other, they share the same models. Some routes will experience a high volume of requests per second and cannot be cached.

I am seeking advice on best practices for properly organizing and splitting these components. I am also open to exploring alternative frameworks, including io.js.

Currently, I am considering three options:

  1. Creating separate apps for each part.
  2. Grouping controllers by folders and devising a method to group routes accordingly.
  3. Setting up another instance of the sails app and running it in a separate process. This allows me to have all controllers and models, but I need guidance on structuring the subapp using this approach.

Answer №1

It seems that opinions may vary, but organizing controllers into subfolders presents the simplest method for sharing models (although not the only method available).

In addition, utilizing these subfolders can facilitate implementing policies as well.

However, it is important to consider other factors related to your question such as shared templates or assets, and whether differences between applications would hinder collaboration. Will all applications utilize the same sessions, or will there be variations?

Ultimately, based on the information provided in your question, sails appears capable of fulfilling your requirements.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Unable to store an empty array using mongoose

After attempting to save the mongoose model: steamBot.items = []; steamBot.save(function(){ callback(); }); However, if steamBot.items is not empty, mongoose will not save it. ...

arrange a collection within an array containing keys as strings

I am facing an issue with sorting an array of objects. I need to sort the 'list' by 'score' in descending order. var list =[{ '440684023463804938': { score: 6, bonuscount: 2 }, '533932209300832266': { score: 20, b ...

Error: Module 'node-rdkafka' not found

After successfully installing node-rdkafka on my MacBook Pro using the "npm install node-rdkafka" command, I encountered an issue while attempting to build the following node.js code in Eclipse. Within my Eclipse Node.JS application, var Kafka = require( ...

npm uninstall can sometimes hang or operate very slowly with no visible activity

I've always noticed that when executing npm uninstall, it tends to take longer than expected. Currently, I initiated the uninstall process for four packages approximately 25 minutes ago, yet it seems to have halted with no visible progress, no noticea ...

Getting both the data by name and its corresponding ID in an Express route parameter using Mongoose

Locating data using ID as a route parameter can be done like this The URL would look something like: http://localhost:8000/products/60d1789867bc6624403ade6e // Fetching a single product router.get("/:id", async (req, res, next) => { const id = req.para ...

The regex routes are now unable to efficiently serve static assets

Question Is it possible to use regex or the built-in URL processor in Express to properly load static files? Expected Behavior Express should match the initial route it encounters and load files as usual. Actual Behavior Error messages indicate that ...

The created date value is missing in the returned object for the voice call

I am currently developing an express/nodejs application that triggers a DB event and then makes multiple calls to notify about a special occurrence. These calls are made using Twilio for NodeJS. However, after making the call, the returned object contains ...

Encountering a persistent Unhandled rejection Error while utilizing NodeJs with Bluebird library

Currently in the process of developing a daemon that listens to TCP connections, sends commands, and listens for events. I made the decision to utilize bluebird to eliminate callbacks, but I'm encountering an issue. I can't seem to catch a rejec ...

Steps to execute an SQL query that retrieves a merged dataset from 2 tables using an ID as a reference

My database consists of two tables: Products Categories When I execute the query SELECT * FROM categories, it returns the following data: [ { "id": 1, "title": "Shoes" }, { "id": 2, "title": "Electronics" } ...

unable to connect a pipe after the response data has been emitted in the npm request

I am having an issue with using the npm request package. I am unable to pipe after the response is emitted in my code snippet below var fs = require('fs'), request = require('request'); var readStream = request({ url: 'https: ...

Is there a reason why the layout.jade isn't functioning properly?

I have encountered an issue with my configure file: The layout.jade is not working properly, even though the jade itself is functioning correctly. I have verified this using Chrome and confirmed that the layout HTML is not being loaded into the page. modu ...

What is the best way to add Chinese characters to a MySQL database using Node.js?

I have identified the root cause of the issue. The problem lies in the delay. It was caused by my input being faster than the MySQL server's ability to process the data. Therefore, I am closing this question and looking for guidance on how to introd ...

How can I retrieve the GET parameters following the "?" in an Express application?

When dealing with queries like this, I am familiar with how to obtain the parameters: app.get('/sample/:id', routes.sample); In such scenarios, I can easily retrieve the parameter using req.params.id (for example, 2 in /sample/2). However, whe ...

Relates to or possesses a singular association in Sequelize

Having two tables in my database, Users and Profile_Education. The Users data is obtained from an auth0/login form, while the Profile_Education is fetched from a node.js/express API. I am looking to establish a foreign key in Profile_Education to link it w ...

Why won't my test in WebdriverJS and Jasmine redirect the browser to the intended URL?

Currently, I am executing a test suite with the following setup: nodejs selenium-webdriver jasmine-node (utilizing jasmine 1.3) Upon running the spec provided below, the browser window initializes but fails to redirect to the specified URL - instead, it ...

Validating forms in express.js

I need to validate a form that includes user details. In addition to the basic validation for checking if fields are not empty, I also want to verify if the username/email exists in the database. For the email field, I need to ensure it is not empty, follo ...

Node.js promises are often throwing Unhandled Promise Rejection errors, but it appears that they are being managed correctly

Despite my efforts to handle all cases, I am encountering an UNhandledPromiseRejection error in my code. The issue seems to arise in the flow from profileRoutes to Controller to Utils. Within profileRoutes.js router.get('/:username', async (r, s ...

Here is a way to prevent a null input value from being accepted in a JavaScript function

Hey there, I have a function that looks like this: class Fun { pem_Files_Checker_And_Adder_Server_Id_Adder(id , serverType , hostname) { //do something }; }; } In order for this function to work properly, I need to give it some values. For exam ...

Update the package.json file by adding a new command to an existing script

Is it possible to automatically run npm install before starting the application with npm start? Here is what my package.json file currently looks like: . . "scripts": { "test": "echo \"Error: no test specified\ ...

The array map is not displaying properly in the table

I am trying to map an array on my webpage and display the results in a table. However, I am facing an issue where the content is not showing up when I compile the page. Can someone please assist me with this problem? When I print the content of a variabl ...