Exposing Meteor to Global namespace - node.js

Using Meteor I used to be able to open up the console and directly call Meteor methods.
console.log(Meteor.userId())
Now I get a reference error that Meteor is not defined. How do I go about exposing the Meteor object?

Just open console and refresh the page (with console open), then Meteor will be available

You need to do var Meteor = require('meteor/meteor').Meteor; in the console to access Meteor.

Related

How typescript requier Nodejs module?

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.

Make a logger for Node Js

I have a project in Node Js, which executes the project on port 3000 and I access from ngrok with my browser to said localhost port, and it executes a server on port 3001 to make requests to a Maria database db. The project is done in react and the server with express.
I want to save the application logs (errors, warnings, etc.) in a log file so that I can see them whenever I want.
My intention was to use winston, and while I have no problem on the server side (3001), when I try to adapt it to the main project, I get an error that it cannot save files (the reason that appears is that it runs from the browser, and you can't create such a file because you don't have access to the project folders)
Can anyone give me some advice? Am I wrong to use winston, and should I use another?
Greetings and thanks
I've never used winston before and I couldn't find anything online about your error. In the past I've always just used node's fs module to create a log of errors and restarts.
const fs = require('fs')
Node's File System Documentation: https://nodejs.dev/learn/the-nodejs-fs-module
Short YouTube Tutorial: https://www.youtube.com/watch?v=U57kU311-nE

How to get nodejs on client-side on cordova?

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.

Using websockets (socket.io) for sails 0.10.x

I am developing a node app on sails, my app needs to do regular exchange of data between server and client
The SailsCast video demonstrates the process for sails 0.9.x, and the mentioned files are not present in Sails 0.10.x
Also the sails doc says we should be using sails.socket instead of sails.io as the later will be deprecated in coming versions
Can any one help me in exchanging data between server and client through sockets. I have done it through node but with Sails MVC, i am not sure how to put the pieces together.
Any reference link or suggestion will be of great help
Thanks
I had the same trouble. You may want to check SailsSocket doc.
If you are loading sails.io.js in your page and haven't changed the default
io.sails.autoConnect to false, then a WebSocket should be created for you.
You can access it via io.socket
Create e.g. assets/js/dependencies/app.io.js with:
io.socket.on('connect', function socketConnected() {
console.debug("This is from the connect: ", io.socket);
console.debug("WebSocket is connected:", io.socket.isConnected());
});
Make sure to load this file after sails.io.js (See pipeline.js).
Open you browser console and double check.
Also check SailsSocket methods
Hope this help you get started

How can I access to my nodeJS app in console on my server?

I have an application nodeJS started like a deamon with forever(https://github.com/nodejitsu/forever).
So now, how can I access to my app and be abble to watch and change values of variables with SSH connexion on my server?
How open console on my app without interuption of service?
thx.
You should give node-inspector a look.
There's nothing built-in for that.
However, you can create a function on the server that will eval whatever string you put as parameter.
To query that function, you can use ajax or socket.io for example.
Socket.io example
socket.on('evalStr', function (str) { eval(str);}); //server
socket.emit('evalStr', "myVar = 10;"); //client via console
Edit: Of course, you can add security such as testing a password before evaluating.

Resources