I've been getting into Node.js recently and I really like the example shown on Socket.io's website showing a real time chat application. However, in all of the examples I see the URL used is localhost:8080 or whatever ip and port is applicable. However, is there any way to implement this into an existing webpage so that it isn't a separate URL? If not, how are these real-time chat apps done in real life?
these sort of questions are usually not meant for stackoverflow, but everyone has been where you are! Stackoverflow is dedicated for code related questions, but this might help you get to your next steps:
NodeJS is a backend server language, you will have to deploy it to a production environment.
New developers typically learn by using services like heroku.com to quickly host backend apps, they take a lot of the complexity of learning Linux or Microrost Server out of the mix, but they are not typically used by more advanced developers.
More advanced (real world apps) run on AWS/Azure/Other hosts.
Implementing it in an existing website requires both frontend and backend languages. Nodejs gives you a leg up in that it's javascript, and can run in both frontend and backend situations.
There are many places online that provide tutorials for creating backend servers and frontend websites.
the list is endless, but some good places for new developers are
https://frontendmasters.com/
https://teamtreehouse.com/
https://egghead.io/
Here is a tutorial on heroku for setting up a nodejs app
Getting Started on Heroku with Node.js
Related
Currently we have mobile app that calls some "APIs" (no backedn yet).
I wonder if it would be ok to use node.js (never used before, I am .net developer) as service (mobile app would call node.js APIs).
And for some dashboard for administrating application, I could try to use angular+node.js.
I have started to learn node.js and angular just a day ago and I wonder if this would work for purpose above.
Yes, you can! Nodejs RESTful API or web services can be used/called by mobile app.
I have developed web-Application & APIs for mobile app on Nodejs, Angularjs, Postgres...
which maintains & used by
Admin Panel
Dashboards
Generating reports (As BI Tools)
Handling thousands of users concurrently & lots more!
Performance is superb! Work like charm
Refer below link, to develop web services for mobile app using nodejs
Designing a RESTful API with Node and Postgres
Basically you want to use the MEAN Stack, check out this blog
https://rclayton.silvrback.com/means-great-but-then-you-grow-up ,
to get the pros and cons regarding the stack usage. You will get rapid development using the stack but need to tradeoff on some features that may be required in the long run.
I just want to say, research before you start your project, because changing the technology afterwards is a huge waste of time and money.
I have searched everywhere for a solution to this problem but for whatever reason I cannot find a clear answer as to how I can carry out this task.
I have built a very simple server with node.js that accesses two numbers from a website API and outputs them onto a localhost port on my computer as shown below:
My question is how can I take my server and make it accessible to applications without having to go into the command line and run the server file? Is there a way I can host it online instead of locally so that I can distribute the application and anyone with the application can pull from this server? What would be the best way to go about accomplishing this task?
Heroku is probably one of the easiest ways to get started with deploying the application: https://devcenter.heroku.com/articles/getting-started-with-nodejs#introduction
However, if you are not familiar with git, Microsoft Azure Webapps is also another great option: https://tryappservice.azure.com/
They both offer free plans which should get you up and running fast!
Question 1: how can I take my server and make it accessible to applications without having to go into the command line and run the server file?
To start a node server you will always need to use the console. If you are not used to,it's time to start :) .
You will be using it not only for node servers but for administrating (almost) every server in the world.
Question 2: Is there a way I can host it online instead of locally ?
There are a lot of nodejs hosting platforms, you can choose between PaaS solutions or IaaS solutions ( AWS EC2, Digital Ocean, etc.) . Probability the easiest way to start ar PaaS services, in this blogbost you will find a good list of PaaS hosting providers. Some of them have free plans.
Take a look at Heroku. They have a free tier (with limitations) and a hobby tier for $7/month.
I have implemented that with Amazon AWS, they offer free option for a limited time, but still great because you have full control on the console, you should be careful while installing the machine on cloud, you have many guides online that you can follow for steps, this one for example has step by step info, try to follow the steps and you will be able to run your app and access it from any public network.
I require some advice in terms of choice of language, I hope that I'm allowed to ask this question here.
To provide some framework information:
As from next week, I'll be following a Java course to get my graduate degree in programming.
For this graduate, they mention that we'll need to develop a webapp in Java.
At the same time, coincidence wants that we are currently developing a webapp that allows users to search popular activities (events) and follow hashtags to render a specific activity feed.
For the front end we currently use some client libraries (Marionette, Backbone, Underscore, Requirejs).
For the server front end (router, rendering server pages), we currently use nodejs.
The question is if it would be a good choice to use Java to build the REST service (to serve both the server and client front ends). The webapp includes a social network, organisers can create their own profile, users can bookmark all sorts of things, ... well, there will be pretty database intensive actions (we'll be using a relatively complex relational model with MySQL).
We might still be using Node to handle push notifications with web sockets but we haven't really discussed this yet.
Since we'll get time at school to work on our project in group, I'd have plenty of time to build the backend REST api with Java which seems like a huge opportunity for me in terms of time. I'm just wondering if there would be any real tradeoffs to do it with Java for this purpose.
Thanks.
I think this would be a huge opportunity to build a REST backend in Java.
Take a look at Spring for a fast and effective way to server HTML
Also you could look at Spring Boot for serving REST APIs. If you follow the tutorials you'll be up an running in minutes.
Good luck
I'm currently working on a web application based on the popular MEAN stack (MongoDB, Express, AngularJS and Node.js). As I am still struggling with some aspects of node.js, I would like to ask for your advice and opinion on a major architecure decision of mine.
As I found Jade rather ugly (notation-wise) and did not want the server to render webpages (for cpu power saving reasons), I chose to always send back prepared html files/templates.
Example:
app.get('/', function(req, res) {
res.sendfile("public/index.html");
});
On the client side, I then initiate further Angular-JSON based communication to realize REST webservices to instantly get and fill in the needed data. Any reasonable arguments against this approach or maybe good points why I should be using a render engine on the server side?
Besides, does anyone know a good online tutorial for a multipage web application featuring user registration/validation, authentication process, rest webservices and so on? Something newbies can take a look at to get a feeling of how to structure a medium to large sized node.js application well? I've been googling for days now but feel that all tutorials I found were always missing essential ingredients or were rather "elementary".
Thanks in advance.
Igor
I started with Node.js like 2 month ago and now I am starting a project following this same approach.
In the same way, I am not using a "render engine", mainly because I am planning to use my client code (angular) to create a hybrid application using cordova (phoneGap).
I learned a lot from the tutorials of Node.js in Pluralshigh:
http://pluralsight.com/training/Courses/TableOfContents/building-angularjs-nodejs-apps-mean
http://pluralsight.com/training/Courses/TableOfContents/nodejs-dotnet-developers
Finally, regarding security, "Passport" is a great library to implement authentication.
btw: I am using Token-Based Authentication.
And the answer to "how integrate Passport with tokens", I found it here:
passport-local with node-jwt-simple
im looking forward to build RT web apps with NodeJS. Coming from Rails, I've felt in love with NodeJS and Async JS programming.
Run a few experiments with Node, and then as I search tools and resources to get used with, I got overwhelmed with the lot of stuff over there.
I found lot's of libraries and components over there, and pretty much got confused on how a large-scale well-writen and implemented RT web app should be built.
So the app will run over NodeJS, using Express framework.
I read about knockout.js, a client-side library to provide realtime stuff like automatic UI refresh, and I guess I could conbine it with jQuery.
Also, I found socket.io.
The author says:
Socket.IO aims to make realtime apps possible in every browser and mobile device, blurring the differences between the different transport mechanisms. It's care-free realtime 100% in JavaScript.
So socket.io is about compatibility.
What about backbone.js? Where does it goes to?
With so much stuff, I got shocked. What should I learn? Which modules worth studing?
Im focusing on NodeJS and Express but most books/screencasts covers old versions of nodejs. So im being guided by its official API.
Now im here asking your advice and to organize somehow all the info out there.
Correct me if my assumptions are not precise, please point me to the right direction and feel free to suggest any other module that could help on my learning.
Thanks in advance
It might be useful for you to separate the node.js server side libraries (via npm etc...) from all of the client side (browser) libraries and technologies like jquery, backbone, knockout etc... when you think about it. Even socket.io which exposes a persistent socket connection between the browser and the server (to avoid polling) does not dictate what client side technologies you use.
Focus on exposing a solid web-api ( random example ) from your server and your client technologies can be swapped, augmented etc... with no effect on the server. The only place they intersect is if you're using a view technology like Jade. It's also an option to have a pure separation where the server is just serving up the client files and your client is a thicker javascript application (using knockout, jquery etc...) calling a good server web api.
Some folks try to unify the client and server models - for example, this article using backbone and node. It depends on how much data you work with to say whether that's feasible but it does couple the client and server and makes the server stateful which can have downsides (scale out, requires affinity etc...). Personally, I get wary of that much magic (binding, state, syncing etc...). Node is about keeping things simple, light and fast. It's a fast front end network server.
My 2 cents (and some may disagree). Start with node on the server and pick your storage (mongoDb etc...). Design a solid RESTful (hypermedia) API - a good webapi regardless of the client. Then start with a basic html/css/js, maybe jquery client and add things like knockout etc... as you expand your client skills. That will allow you to replace your client technologies independent of your server as the new technology winds change (and they will).
That's the hallmark of a well designed system - the ability to replace componets/sub-systems without rewriting everything :)
Hope that helps clear up some of the fog :)
You may want to look at Meteor if you are focussing on real-time Javascript apps: http://meteor.com/