Node.js + Node-Webkit + Node-SerialPort Based Application - Is this Possible? - javascript

I am new to Node.js and before I go head first into taking on a new technology and migrating my c# based application, I wanted to make sure what I had in mind is possible with Node.js and if it is recommended.
So please let me know your opinion!
My application has the following requirements:-
TCP server (to receive packets from TCP clients such as smart phones, computers etc.)
Serial port access (To control a hardware device)
Web server facilities (to serve HTML5 pages or provide web services intefaces)
Simple native app like GUI for configuration.
All of this needs to be packaged nicely for end users to install simply.
Why I would want to do this you may ask?? The reason I am most interested in using Node.js is due to the cross platform nature, including the ability to install on cheap single board/embedded computers.
This is my thinking:-
Node.js - to provide the TCP server, serve HTML5 pages and provide web services interfaces.
Node-Webkit - to provide the simple native app like configuration interface. I also believe that it provides the ability to package my application for simple distribution, but I am not sure? (I could leave out Node-Webkit if there was another way to package my app for simple distribution. Although it is preferred as even having to find the IP Address of the computer so as to access a web browser interface would be tricky for some of my users.)
Node-SerialPort - to provide the ability to communicate with the hardware device. The instructions will come from 1 of three sources. 1) TCP connection 2) HTML5 Webpage Initiated 3) Web Services Initiated.

That's what most people use Node.js for
https://npmjs.org/search?q=serial+port
Again, that's what most people use Node.js for
Because of 1 and 3, the most obvious UI for node.js apps is the browser. Write a config page to control your app. Using node-webkit is overkill, just use whatever browser is already available. Node can run multiple listeners on multiple ports, serving the same app.
npm install is pretty simple.
Go learn how to write simple Node.js apps (with express for easy http servering, and jade or nunjucks for easy html templating) and then move up from there.

Point 5. I understand the fact of having an installer. I would suggest that the .msi or .exe will create a Windows Service for NodeJs. Then the node js server will launch at Windows startup and the end user will access the browser with
http://localhost:< a port number>/.
Packaging NodeJS : To package nodejs, you can copy the nodejs.exe from the installation directory of nodejs into the directory where you developp the node application. Then zip everything. You unzip it on another computer and it will execute.

Related

Can I run programs/CLI using a PWA?

I heard PWA is capable of more things than a regular web app when it comes to client side operations.
As a disclaimer, I'd like to note that the PWA I've been working on is a privately used project, it has no malicious intent to harm any system.
What I want to do is I want to be able to use cec-client to turn the TV on/off on the system, so I want to be able to either run a pre-written bash script, or access CLI on the system. Is it somehow possible using a PWA? Currently the client system has a simple nodejs app that's listening to a call on localhost from the web app, which in turn turns the TV on. I want to change it to a more sophisticated solution, hence I'm wondering if PWA can run scripts on the client's system.
The system that you are currently using (server side code with access to the necessary API) is likely the best method.
Progressive Web Apps are just websites with some extra features to persist state and emulate some functions available to system apps, and the security risks that would be involved if they could execute arbitrary system code would be enormous.

Is there a way to build a Remote Desktop Application in nodejs that runs on browser?

I want to build an application that runs on the browser to handle pc remotely, where the frontend is on Reactjs and the backend is on Nodejs. Thank You in advance.
In addition to specifying what technologies you want to use, you should tell us why. What requirement are you trying to fill? You may not need React or Node.
Without Node, there are a few React components already made for noVNC:
react-vnc
react-vnc-display
Those components require a VNC server. Here's a snippet from the noVNC readme:
Server Requirements
noVNC follows the standard VNC protocol, but unlike other VNC clients it does require WebSockets support. Many servers include support (e.g. x11vnc/libvncserver, QEMU, and MobileVNC), but for the others you need to use a WebSockets to TCP socket proxy. noVNC has a sister project websockify that provides a simple such proxy.
Source: noVNC
Using Node, you could use the following packages:
guacamole-lite
node-rdpjs-2
You would then need to build a React component for the RDP/VNC display similar to react-vnc and react-vnc-display. guacamole-lite accepts websocket connections so you may be able to use one of those two React components with it.

How to detect a server in the network using JS?

Basically, I want to make a peer to peer architecture, using JavaScript (Ionic).
Since, JS cannot create sockets/etc; a NodeJS server has to be introduced between the clients; acting as the Socket.IO server between the clients.
The problem with this, is that the Socket.IO (NodeJS) server would need to be automatically found within the local network -- by the clients (instead of hardcoded/configured).
Are there any ways to implement such a thing; or alternatives to this architecture?
Thanks for the help!
Are there any ways to implement such a thing; or alternatives to this architecture?
Currently your architecture is using a browser app plus a Node app that users need to have on their network just to create TCP connections.
What you can do instead is create an Electron app that combines a Node app, a browser app, and a browser itself. See:
https://electron.atom.io/
With Electron you can write your frontend code almost the same way as for the regular browser, but you can use the entire Node API including the TCP sockets so there will be no need to create a separate Node app and to search for that app in the network. This can greatly simplify your architecture.
Note: this is not an answer to the first part of the question: "How to detect a server in the network using JS?" but to the second part of the question: "Are there any ways to implement such a thing; or alternatives to this architecture?" Detecting the servers on the local network with client-side JavaScript will not be easy - and in fact it shouldn't be even possible because websites being able to scan your LAN for active services would be a serious problem for privacy and security.

How to convert node.js application into cordova

we built a node.js application for desktop and tablet. It's completely web based application. Now I am planning to implement same application as native app in android using Apache cordova.
Under project directory, we have node_modules,public,.... all client side files are in public folder. When I invoke URL in browser, from client side I am making API call to check whether user already logged or not. like this we are making API calls to my server.
As per my understanding,native app is nothing but we are storing all the client side files into device. whenever user open app will load client side files and as per work flow it will make API calls.
Theoretically I understand that much.
where I stuck :
In desktop app , I used to make API calls with URL like /api/web/shared/reject/, here we don't need to mention server address like localhost:8080/api/web/shared/reject/ that everything browser will take care. This same thing how can I make it work in cordova applications.
How cordova will know whether it is localhost or something else...
Regarding this, I Goggled but I didn't find any tutorials.
can anyone suggest me the way.
Basically, is a concept problem.
Node.js is a technology specialised in backend and some of usages like extend some services/functions, etc.
When you talk of a localhost:8080 you are talking that your node.js implementation should be in a server (Amazon, Azure, your own server, nodejitsu, etc), and the public pages or the pages that the client should consume will be added into phonegap, specifically in your www directory and the references for localhost:8080 should be changed for your server (Amazon, your own server, nodejitsu, etc), and the files on your www directory could have references (via GET or POST to retrieve the data from the server. Remember, the Crossdomain problem doesn't happens on phonegap (maybe in a local enviroment should occur).
And Phonegap is a framework to develop front-end with HTML5, jquery, CSS3 and other releated technologies.
For your specific case the node_modules should be installed in the server too, not on the phonegap project.

PostgreSQL connection via javascript

I am searching for a way to connect to postgresql directly in the browser. Im trying to utilize nodejs and browserify but have had no luck so far with the bundling. Whenever I compile a script that contains a
require('pg')
it specifically states in the browser:
Cannot find module '/node_modules/pg/lib/client'
the browser tells me afterwards that he is not able to find the modules that pg requires. Maybe i need to bundle pg with browserify before ?
I appreciate if somebody has an idea on how to work on this or even a suggestion how I could connect via javascript to pgsql.
While some node modules may be generally reusable to some degree in a web browser, most take advantage of Node.JS specific features or drivers and cannot work in any web browser. A case like a Postgresql package is a perfect example, as it requires many functions simply not present in a web browser.
If you look at the APIs of Node.JS (http://nodejs.org/api/), these APIs are not available in the browser (some could be emulated, but many are file system, low level sockets, binary modules, etc.).
If you want to use Postgresql, you'll need to build a web server layer, and expose an API of your own (likely a RESTful style api) and call the web services to perform the database actions you want to use. You could look at using Connect or Express to make writing the web service layer more convenient.

Categories

Resources