logging in a table like pm2 with nodeJS - javascript

I want to format all of my script's logs into a table for clarity purposes. Kind of what pm2 (process manager 2) does atm for example.
As of today I use console.table(logs) where logs is an object of variables I want to keep track of. It works great but I want to get rid of the trailing \n that console.table includes.
I would want to do something like: process.stdout.write(table(logs)) where I don't have to create the table function myself.
I tried to find the source code of console.table to copy it and remove the trailing newline as a utils function without success. any idea?

The npm package c-log does a wonderful job at this : npm c-log

Related

Ignore lines running debuggers like pdb.set_trace() or debugger in the repository?

Sometimes when I commit my code in python or javascript, I forgot to remove the debuggers, so I must do it manually.
I know something about creating a .gitattributes file at the root of the project with the following code:
*.py filter=import pdb; pdb.set_trace()
*.js filter=debugger
But when I commit the code, it saves the lines in the repository anyway.
How to remove or at least comment these lines in the repository, and put them back in the working directory?
Try commenting the unwanted lines out, in js this is done by putting the // operator before unwanted lines.
In python this is done by the # operator before the unwanted line
for instance
#filter=import pdb; pdb.set_trace()
And for js
//filter=debugger
Opinion: the filter option in a .gitattributes should not be used the way you're trying to use it. Even if you fix the syntax, this is a bad idea.
The actual problem is that the syntax for filter lines in .gitattributes is simply:
filter=<name>
You must then define this filter (one whose name you substitute in for the angle bracketed expression) in .git/config or your global .gitconfig. For instance, if you had a filter named hack-debug-lines-in-python, you might have:
*.py filter=hack-debug-lines-in-python
in the .gitattributes file, and then:
[filter "hack-debug-lines-in-python"]
clean = ...
smudge = ...
in your .git/config. You would need to fill in the three dots here with an actual program that can do the debug-line trickiness that you want.
You will need to write this filter program. Git does not include one.

Is there a root keyword in JavaScript or why does Sublime display it like this?

I used a variable called root in a recent JavaScript project, and Sublime Text 3 displayed it like this:
So I'm wondering if there is a root keyword in JavaScript, and if so what does it do... Otherwise I'd like to know a way to stop Sublime Text from displaying it differently... The console, however, says ReferenceError: root is not defined when I type it in there.
root used to be a variable in Node.js however it was deprecated in v6.
UPDATE:
The old URL doesn't work anymore, so I've updated it with the Internet Archive's Wayback Machine's version of it, also here's the merge request with the change.
The declaration comes from this file in Sublime.
UPDATE:
To remove the syntax rule, install PackageResourceViewer as per the instructions here and then open up the JavaScript.sublime-syntax file, find the word root (there's currently only one) and remove it (and the following | character).
Note that you'll need to run Sublime as an administrator on Windows in order to edit the file.
It seems root is not a keyword of javascript:
https://www.w3schools.com/js/js_reserved.asp

convert executable to node module/object

I tried searching, but with not luck.
I want to convert/wrap an executable to use it easily and nicely in node, and not calling child_process.exec all the time.
For example, if I wanted to do it with git, instead of git help or git clone git://repo.git I'll have somethings like:
var git = new cmd('git');
git.help();
git.clone('git://repo.git');
etc..
Doe's anyone knows if something like that exist?
The closest thing I've found so far is run-cmd which can do somethings like that but not automatically. I'll need to create the object with all the parameters I want.
Thanks,
Ariel

How to develop a javascript library from an already existing npm module (codius)

never done this before.
I'm using https://github.com/codius/codius-host. CodiuĀ§ development has been abandoned, but I want to salvage part of it to use for my own project. I really need to be able to run codius commands from browser, so I need to develop a library or what you call it.
var codius = require('codius')
codius.upload({host: http://contract.host}
codius-host comes packed with command-line integration,
$ CODIUS_HOST=https://codius.host codius upload
How do I make a .js script do what the command-line command does ?
also posted on https://stackoverflow.com/questions/31126511/if-i-have-a-npm-tool-that-uses-comman-line-commands-how-can-i-create-a-javascri
hard time asking this questions since don't know where to start. help.
Assuming that you have access to the codius-host source code you should find the piece of code which manages the command line arguments. I am sure that they do handle the command and the command line arguments from an entry module/function and than later delegate the real job to a different module/function. What you need to do is to provide correct parameters to the functions which the function/module that handles command line argument calls with command line parameters.
In addition to that there are some nodejs libraries that might imitate a command line call from the program itself. One of those I know is shelljs:
https://www.npmjs.com/package/shelljs
You might want to check this out as well. With this one without bothering with the source code you might be able to imitate command line behaviour.

How do I use Jangaroo to convert a single As3 function to javascript?

I've stumbled upon Jangaroo, and it seems to provide what i need. The problem is that to use it the docs say that i need to setup maven.
I really have a single function, so all that is a bit of an overkill.
The ideal solution would be something similar to the Telerik Code Converter(http://converter.telerik.com), but for AS3.
I just updated the documentation on how to use Jangaroo as a command line tool:
https://github.com/CoreMedia/jangaroo-tools/wiki/Stand-Alone-Compiler
After following steps 1 through 6, you can compile your single class like so:
mkdir joo\classes
jooc -v -g SOURCE -classpath %JOOLIBS%\jangaroo-runtime.jar -sourcepath . -d joo\classes GACodec.as
Note that the generated JavaScript file GACodec.js only works together with the jangaroo runtime. The Wiki page continues with instructions on how to end up with a working Webapp. For your class, you just have to unpack jangaroo-runtime.jar:
"%JAVA_HOME%\bin\jar" -xf %JOOLIBS%\jangaroo-runtime.jar
Then, you can run your class from a tiny HTML file that looks like so:
<script src="joo/jangaroo-runtime.module.js"></script>
<script>
joo.classLoader.import_("GACodec");
joo.classLoader.complete(function() {
alert(new GACodec().encode("FOOBAR!"));
});
</script>
When trying out your code, I noticed that it needs a minor change to work: Jangaroo does not generate implicit initialization code for typed local variables. There are at least two lines in your code where an integer variable is declared but not initialized explicitly. ActionScript would set it to 0, but Jangaroo does not. Anyway, it is better style to do explicit initialization, and if you do so, i.e. in your source code replace
var i:int;
by
var i:int = 0;
as far as I can tell, it seems works!
Last thing, I find using Maven easier than installing the Jangaroo SDK, since you just have to install Maven once and it takes care of all needed downloads and makes updating to the latest Jangaroo version a breeze: Just increase the Jangaroo version number in your pom.xml, and Maven takes care of everything else.

Categories

Resources