I am trying to connect and query my MS SQL DB from Javascript in a browser (i.e. Chrome, NOT IE do not want to use ActiveX controls). In order to do that I found this Node library Tedious and Browserify.
Tedious provides API to connect and query MS SQL server. Browserify would walk over the dependency tree and generate a bundle.js with all dependencies.
So I tried to Browserify Tedious so that I could connect to my DB straight from my client side javascript running in the Chrome browser. The error I get is that the Socket object in the net package is undefined. Any idea why?
Edit 1
Thanks Peter for the response. Ok Browserify was a stretch.
Can I use websockets to connect and perform SQL queries in my MSSQL db? In other words, can an ODBC driver be written in JavaScript using WebSockets? I know this is going to be insecure. But this is meant for in-house only behind a firewall.
I don't believe it is possible to run tedious in a browser. Browserify is powerful, but not magical, despite the wizard mascot icon. Node.js provides filesystem, networking, and child_process APIs that are not available in the browser. In a few special cases, browserify magic can make certain things you expect to be node-only work in the browser, but generally a module will have to be pure JavaScript or JavaScript using official web browser APIs (DOM, AJAX, WebSockets, etc) to work in the browser.
This is a package that works well with browserify :
https://www.npmjs.com/package/net-browserify
It's based on a websocket proxy.
Related
I have an idea for a side project where i will connect two terminals(clients) using WebRTC and they will share some data with each other(assume a CLI chat app) using Node.js. But wherever i read about WebRTC it always says that it works only in browsers. Like the fact that if a machine does not have a browser that supports WebRTC then it would not work in the machine. Do statements like these mean that WebRTC can only work in the browser. If not then how should i approach making something like this?
The functions i want the application to have :-
1.) It should connect with the peer when i write "node client.js" in the terminal (client.js will be the client script).
2.) The terminals should be able to send each other messages.
3.) No need of the browser.
I've made such applications using WebSockets and i dont intend to use them in this project.
Yea this is possible, and people are doing it today!
Check out ascii it is a command line WebRTC client that does camera capture and encoding. It uses the Golang library pion/webrtc
I am sure it is possible with nodejs as well, but don't know how much work it would be.
Also if you are doing chat only it is even easier! See pion-to-pion really easy example to have two processes communicate via WebRTC.
I understand this is not best practice but I am operating within a limited realm and, as far as I can tell, this is the only solution to this problem.
I am trying to connect to an MS-SQL database both to get data and to put data onto the database. I cannot seem to do it through JavaScript.
ActiveXObject is, from my understanding, now depreciated so that is not working, which eliminates every functional solution that I could find recommended in the past.
Please note: I am not a web developer and I have no access to any of the standard web development tools for this task.
This is the question has been asked multiple times in various forums - Can my client-side Javascript (running in a browser) connect to a database server and fetch data?
The short answer is - not recommended in general, not feasible without breaching security and without using outdated technologies. Let us dig into it.
It is possible to connect to remote database from a browser using outdated technologies
There are two pieces of technologies from Java and .Net worlds - Applet and ActiveX that run on the browser and can communicate to a remote database. The Java Applet is hardly used by anyone nowadays and browsers are stopping to support it. ActiveX is discontinued by Microsoft in their newer browser Edge. So, you have to enforce your target users to use old insecure browsers if you want to go with these options.
Do not use this.
Use databases embedded in the browser and sync with a remote database
You may use the database locally available in the browser and perform all read/write operations. Periodically sync this database with a remote one. Here are the options:
MongoDB and use change stream to sync with a remote MongoDB
PouchDB and sync with a remote CouchDB or even a MySQL database
Use this only for offline storage temporarily in the browser.
The traditional and secure approach to connect to a remote Database
Use a server-side technology to develop an app that your client-side code (Javascript, HTML) talks to. The app may provide RESTful APIs to interact from the client-side. Then the app that is running in a web server connects and interacts with the database. There are plenty of server-side technologies such as Java, PHP, Python, NodeJS (Javascript based), .Net, etc. to develop your server-side app.
Go with this option.
Well javascript is a client side scripting where as your database runs on a server. So firstly you cannot connect to a database for executing any query from client side i.e javascript and also you need to setup a server side service which can connect to the database and execute the query and give you the result at the client side. You can refer any client-server architecture for this on the web.
I am a designer interested in making a shift to iPhone App Development. I am looking to spend the weeks after my exams studying how backend and frontend iPhone development works.
If I want to ultimately build an app which requires a frontend work in ObjectiveC/Xcode environment will I be able to use Node.js for example to compile user data and databases for backend data?
As I understand it (please correct me if I am wrong) to do an app which connects to servers for data requests you need a backend development. I have been reading about node.js and it seems very fast and its javascript which I like.
What would be the easiest combo to get into. I really am not technical and want to limit the pain for compatibility issues.
Will Objective C and Node.js be compatible?
Do you have any outside recommendations with experience you like to share?
Thank you
At a high level, any web server that has the ability to accept http requests and respond with some content (JSON, XML, HTML, string...) will work, you just have to use the correct methods for submitting the request and parsing the response.
Personally, I've been using node.js for an API that I created and host it on AWS. It's lightning fast and I've had no issues. As with most programming languages today, objective-c has libraries that allow you to submit http requests and parse JSON responses.
Node.js supply web interface just like any other backend stack you can choose, so it is suitable for iPhone backend development.
You can also skip the entire backend development, hosting solution and DNS boilerplate if you wish, by using backend as a service solutions like Parse or Stackmob
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.
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.