Is there some way to create http server on Dart that will be compiled to JS for Node JS?
If I try to use default server
HttpServer.bind(new InternetAddress("127.0.0.1"), 8081);
and then compile this code via dart2js I'll get error when node started
Unsupported operation: InternetAddress
You can't use dart:io when you want to build to JS because dart:io won't be available where the build output runs.
dart:io forwards to operating system calls and dart2js doesn't have any ability to translate such calls to JS (actually Node.js because JS itself doesn't provide any way at all)
You might need something like https://github.com/luizmineo/node-webkit.dart to use a custom implementation that translates to quivalent Node.js calls.
Related
i read many similar question
this is the workaround i am trying now
for example to mysql module in Nodejs
1.
cmd enter:
npm install typescript
npm install mysql
typescript write:
import * as ms from "mysql";
// i see some people write " import ms = require("mysql"); ", but i get the error
then i check console window in chrome devtool
i see error " Uncaught ReferenceError: exports is not defined "
and this error seems to stop script from keep running.
TypeScript will, by default, transpile to JavasScript files using the CommonJS module format which browsers do not support.
You can configure it to use ECMAScript modules (which are supported by browsers).
However, the mysql module depends on APIs that are available in Node.js but not in web browsers so you cannot use it in a web browser.
You could write a web service (e.g. using Express hosted by Node.js) which accesses the database and then interact with it from the browser using forms, Ajax or Web Sockets.
I am making a app with cordova. I want the coinmarketcap stats in it. I am using nodejs and it is working fine when I execute it in my command line. However I want to use it in my cordova application. This is the link to the npm package https://www.npmjs.com/package/node-coinmarketcap
When I try to run it in a browser I get the error message require not defined. I believe that error comes because nodesj is a server-side and browser is a client side ? Am I correct ?
My code
var CoinMarketCap = require("node-coinmarketcap");
var coinmarketcap = new CoinMarketCap();
coinmarketcap.multi(coins => {
console.log(coins.getTop(10)); // Prints information about top 10 cryptocurrencies
});
I expect that I can run my code in my browser or cordova application.
You are right, Node.js is a JavaScript run-time environment that executes JavaScript code outside of a browser. You have to find some client-side JS code or execute your node code on your server and send result to your Cordova app.
We are trying to get gRPC to work with React (actually we were trying to get it to work with React-Native but gave up on that for now).
Using plain node.js things are pretty straight forward if you follow this example.
We started by using create-react-app but when we started the app, we got the following error:
existsSync is not a function
That was casued by this bit in pre-binding.js belonging to the node-pre-gyp package located in grpc:
var existsSync = require('fs').existsSync || require('path').existsSync;
My understanding is that something goes on with Webpack (or some other process run by create-react-app) that goes and returns and empty object instead of require('fs').
Any ideas of how to get this to work without having to give up on the wonders of create-react-app?
To test it out you can just follow these 2 easy steps:
create-react-app test-app
add import grpc from 'grpc'; in the App.js file
Basically, from what I understand now, you are not really supposed to use gRPC + Protobuf directly from any frontend but rather it is more common to use the grpc node package on node.js server-side code and then communicate with the browser-side code using Express.
The server-side code on node.js then communicates using grpc with the microservices.
We are testing out the use of Firebase Functions to communicate securely with the frontend and Firebase Functions communicate with the Go microservices using grpc.
I am trying to set up Angular 5 project in Electron and also run nodejs in server side, i know that electron permit to create desktop app, but is it possible to create server side app with electron, also i'm not sure if it's possible to have the nodejs app and angular all in the same project with ngx electron.
If I understand you correctly, you want a desktop application that in some way also communicates with a server.
Sure, that's possible since Electron will bundle node.js in the generated binary.
The easiest way I can think of is setting up an HTTP API (e.G REST) on your server side (possible with any language, I'd recommend either PHP or Node.js) and use http in your ng/electron app to talk to the server.
http.get(options, (res) => {
// Do stuff
}).on('socket', (socket) => {
socket.emit('agentRemove');
});
I try to use node core module fs in reactjs.
const fs = require('fs');
but it is throwing error: "can't find module fs". can we use node core module or other module in front end side(react js) using webpack. if yes then how can we achieve this and if we can't, then is there any way to use node module in front end side ?
Using a node module in the front end can make sense, but in the case of fs it doesn't. The file system of the client computer is not exposed to the code running on a website.
This is enforced for evident security reasons. You cannot circumvent this barrier magically using a node module on the client side.
The short answer here is : no, you can't.