I am getting in nodejs development. Until now everything is perfect, I've got my nodejs server running using expressjs as backend framework but I've found a problem, all nodejs tutorials included expressjs create unique server.js file and my code is messing up. All rountimes and functions live there and that's why I want to create an MVC pattern for my backend but I don't know how. I've tried to create a nodejs module but I failed in trying.
Someone can tell me how do I construct an MVC structure in backend as my frontend (I'm using Backbonejs)?
Here is an example of MVC style controllers using express: https://github.com/strongloop/express/tree/master/examples/mvc?_ga=1.227384661.999716043.1382977119
This example was pulled form the FAQ page on expressjs.com. The documentation there is really quite good.
Edit: If you change your mind about MVC look at the "How should I structure my application?" section of the FAQ for examples of other patterns.
Related
I'm currently making an application using ReactJS for the front-end and NodeJS for the backend, however, I'm confused regarding how to connect those two.
I read about both, server-side rendering and client-side rendering.
I followed this tutorial (https://www.fullstackreact.com/articles/using-create-react-app-with-a-server/ ) as to how to connect my ReactJS app, which I created using creat-react-app and my node backend, however, I read that the solution of adding "proxy": "http://localhost:8000" (or whatever port node runs on) to the package.json file is only suitable for development.
Anyway, what I would like to know is: What is the best way of connecting ReactJS and Node.js if the user should be able to enter,delete or update data, which is saved to a database?
You should check out Nextjs. It is based on React and NodeJS.
I believe this is exactly what you are looking for. It is an easy-to-use framework that handles all the difficult stuff when it comes to server rendering while keeping the frontend async and dynamic. Besides that. When you get better using it, you can do in dept configuration to optimize to you need. Hope that helps.
Try out one of the examples on the git repository.
I have a Meteor.js app similar to this one -> https://www.youtube.com/watch?v=66DH69e-wJ0&t=936s as my first Meteor.js app.
And I have created a API.ai chatbot.
And now I need some guildlines of what should I learn/read to achieve something like this:
I want a function to send user messages to the api and then posts
api's answer into the chat.
It's hard to answer your question if we don't know any details, but I would suggest to read carefully Meteor tutorial. Depending on frontend library you use:
Meteor tutorial for Blaze
Meteor tutorial for Angular
Meteor tutorial for React
If you would like to use other libraries the best place to start is the GitHub repository with Meteor integration for this library. For example Vue.
Secondly, you should read Meteor guide. You will find here tons of useful tips.
I took a quick look at the video you included and API.ai. I guess that you will need this node package. Also, take a closer look at Methods section in Meteor guide. You will need them to use API.ai package from your client side. When you work with third-party APIs you should also read about HTTP package.
I have a MVC project where the web portion is in Angular JS. It was asked of me to create a DB project which I did. We are now concerned with the Angular JS fetching data. Currently there exists a couple of project in the solution representing EF, and in the web project a Web API that interacts with EF, however it is incomplete. However I was considering using an Angular JS Module, Controller, and Service that will communicate with a MVC controller returning a JsonResult as shown here:
Angular JS with MVC Example
Since I created the DB project, I don't really feel the need for EF, but maybe this is a bad practice.If there are any suggestions on what is the standard practice to best fetch data for Angular JS I would love to know as I'm having a hard time pinning what approach is best for my scenario. Thanks.
I've come across a lot of posts on Stack Overflow about Express.js being used with Angular.js and how there are two MVC components to both the client and back-end sides of the web application, but I've just become confused now. What are the components of a web application, and what does each of these two serve? What are the MVC parts for each of the client and back-end sides exactly?
Thanks in advance for any response!
In most cases, it's pretty straight forward. In my applications, it generally works like this:
Express.js provides the backend REST API
Express.js serves up the static HTML, JavaScript, CSS and image assets.
The frontend HTML/Javascript bits are written using Angular.js.
I tend not to use any of Express.js' view capabilities (the stuff that provides functionality similar to ruby on rails or Django, with templating and all that), but instead serve up a single index.html and then let Angular.js do the rest. It's very possible/typical to make an Angular.js app which has only one main HTML file and therefore the "view" pieces of express are unneeded.
Angular.js itself is structured in an MVC fashion. You have view templates and controllers which provide data to them and handle events from user interaction. The data the controllers act on from comes from the model. The model is simply a layer providing access to the API provided by the Express.js backend. This is typically done using Angular.js resources.
RESTify is another alternative to express for apps stuctured in the way I describe.
As others have recommended, just go through the tutorials on each component's website. I also found a tutorial about integrating Anguar.js and Express.js here: http://technokayiti.blogspot.no/2013/06/lesson-5-angularjs-tutorial-backend.html
I recently installed a web app which use Symfony2 framework and Apache Thrift.
Now I would like to make backbone usable in Symfony2 framework.
My question is about Backbone.sync.
How can I override/use Backbone.sync in order to get data from the server in a web app using Symfony2 framework and/or Apache Thrift ?
Are there some tutorials on the web for do it? I just found this one Symfony + Backbone.js for highly dynamic apps, but it doesn't say nothing about how to get data from the server.
By default, Backbone.js and its sync method can work with REST APIs without any modification. So if you can create a web service with Symfony2 that can handle GET/POST/PUT/DELETE and return JSON, you should be good to go.
I'm not terribly familiar with Symfony, but for a basic REST API, you'll need to define your URL routes (e.g. "www.yourdomain.com/api/items"), and then create methods to perform actions based on those routes (e.g. return records in JSON encoded format).
Here's a quick tutorial on creating a REST API with Symfony2: Symfony2 REST
Also, check out Wine Cellar tutorial on the Backbone tutorial page. It uses PHP Slim framework, but the backbone.js concepts will be exactly the same, because as long as you are using a basic REST API, backbone is back-end agnostic.
Check this bundle https://github.com/gigo6000/DevtimeRafflerBundle it's a small simple app that includes some basic REST actions. This was created with https://github.com/gigo6000/DevtimeBackboneBundle