The same code for client(Angular2) and server(nodejs) - node.js

Is there a way of using the same code for both Anglular2 models and mongoose models on express.js? The same question goes for Angular2 validation forms and express.js validation post requests(obviously one have to check the data twice on the client and on the server).
I moved from php to nodejs in hopes to avoid duplicate code. So how do I exactly do this?

Related

Use VueJS with sailsjs

How do i use vuejs with sails js. I want to list and create dynamic content using Vue. How do I create route for CRUD operations for objects like posts and comments ? How do i check authorization on every route that the user must be logged in for this route to work. One more thing , how can I test the crud operations using Postman
Thanks
You have two ways of using VueJs in Sails.
The view layer of sails js is built on Vue.js, so you can use the native implementation of Vue.js as described in sails js doc.
Or, you can setup a Vue.js standalone app, and make it dial with you sails.js backend by the way of http requests that can you send with http, axios, ... packages .
In both cases, you're gonna use the entry points that you will define in your routes.js file of sails > config folder which would corresponds to controllers that contains your CRUD requests. That is also the way you have to test your "CRUD" operations with postman, by requesting your entry points.
For authorization, a good practice would be to use the policies of Sails.js :)

Does any one know about simple CRUD operations example in ReactJS and Nodejs?

I am beginner in Reactjs and Nodejs.
I just want to build a simple application which performs CRUD operations.
ReactJS for displaying data and act as a front-end.
Nodejs have some API which returns static data.
If anyone know about some blog or have some example with you than please share. This will help me to start with this.
I also searched for many articles online but they all are consist database connection, ExpressJs which i don not need at this time.
You can see here:-
In this repository you can see crud operation in reactjs and nodejs and mysql database used here.
https://github.com/abhi4pr/express-react-app

Structure Node.js (Express) app

How should I structure Node.js (Express) app? I do so:
app.js - starting the server
router.js - routing requests and starting functions from other files.
pages.js - render not-static pages. Example: request to database and render result
control.js - operation with alteration. Example: creation/updating line in database.
db.js - connection to database and creation model for ORM.
What should be changed? How to do better?
(Sorry for bad english)
Have you heard about Yeoman? It is a webapp generator, which is a very useful tool to automatically build webapp skeletons.
There are a lot of different generators of any web technology/framework you wish to use. Maybe a good idea can be having a look and exploring how these generators structure the code for you, which could give you an idea in how to keep your code organized.
You can Search for generators at Yeoman's site, just type Express and try different ones.

Website Architecture for Node, Backbone+Marionette, Mongo DB GridFS

I am programming a website with a node.js and mongodb grifs on back-end with backbone and marionette as front end frameworks.
As I am new to creating single page applications (SPA) I may be wrong in any of my assumptions, please correct me wherever I am wrong.
The way I understand the flow of control is:
As soon as the first request to the server is made to abcxyz.com, nodejs server serves the base html file via a get request from the server.js file. This html file links to the main.js file which holds all the backbone+marionette models, collections and views.
As my aim is to write a SPA (single page application), I assume that from here onwards the flow of control remains completely within the main.js file as it is the file which handles the url routing (think of #routes for emails in gmail).
Now my question is this: How can I carry data to and from the mongodb gridfs database for each route change in backbone. Putting another way - how does backbone interface with mongo database which can be accessed only in the server.js file, and how do I communicate a change of route (hence a change in the data needed for backbone views) from backbone to the node.js server?
I'm sorry for a really long question, feeling very confused :(

Can Express routes be used as MVC Controllers in Node.JS Apps?

I have been playing around for a bit on Nodejs, so forgive me if my question might look stupid.
When I setup a new nodejs app with express, I noted that it created a folder /routes that basically does what it suggests.
Now, is it ok to use said file(s) as the Controllers for my app?
I think so. Because role of a route in express is to decide what to do when a certain request comes, such as getting data from a model or rendering a view with some data and this is what controllers do, right?
You can see in official examples that routes are actually placed in a folder named conrollers.
https://github.com/visionmedia/express/blob/master/examples/mvc/controllers/pet/index.js

Resources