Hot answers tagged

3

there is no right in wrong in this situation it's a question of what's best for your particular situation if you are going to build many Rest API endpoints it's best to separate them in separate files under routes like this so your code can be more maintainable : │ ├── routes/ | | |___index.js |___auth.js |___gizmo.js ...


3

You have just added an unneeded layer of complexity to the problem. You can just create the factory as an Object const factory = { select(opts, text) { return (<select options={opts} labelText={text} />) }, input(opts, text) { return (<input labelText={text} />) }, default() { return new Error("Value Not Found") } }; Then call the ...


2

Your code does not work - process.hrtime() does not return with a timestamp of any useful form unless you compare it to another process.hrtime() in the same running program (typically used for measuring performance). From the documentation: These times are relative to an arbitrary time in the past, and not related to the time of day and therefore not ...


2

the code has plenty of room for improvement, and yes it violates the solid principals like the Single responsibility principle "your functions are way too big and the module in itself has too many responsibilities ", to clarify there are no rules on how API should be written in NodeJS there are code practices and design patterns that help us developers ...


1

Some comments: Use the built-in database promise support in mysql2 rather than promisify stuff yourself. In Model, don't hide low level database errors. If the database has an error, let the caller see the error. It's up to the caller what to do with errors. There's no reason for your Model.getStats() to be async. Service should use promises to ...


Only top voted, non community-wiki answers of a minimum length are eligible