Here's how you could create custom error classes in Node.js using latest ES6 / ES2015 syntax.
I've tried to make it as lean and unobtrusive as possible.
errors/AppError.js
{ | |
"targets": [ | |
{ | |
"target_name": "example_addon", | |
"sources": [ "example_addon.c" ], | |
"include_dirs": [ "<!@(node -p \"require('node-addon-api').include\")" ], | |
"dependencies": [ "<!@(node -p \"require('node-addon-api').gyp\")" ] | |
} | |
] | |
} |
/* test load from stream | |
* | |
* compile with: | |
* | |
* gcc -g -Wall load-from-stream.c `pkg-config vips --cflags --libs` | |
* | |
* test with: | |
* | |
* cat k2.jpg k4.jpg | ./a.out | |
*/ |
'use strict' | |
const { EventEmitter } = require('events') | |
function print(evt) { | |
console.log('#####') | |
console.log('Event: ', evt.name) | |
if (evt.data) { | |
console.log(evt.data) | |
} |
#!/bin/bash | |
echo "Node Linux Installer by www.github.com/taaem" | |
echo "Need Root for installing NodeJS" | |
sudo sh -c 'echo "Got Root!"' | |
echo "Get Latest Version Number..." | |
{ | |
wget --output-document=node-updater.html https://nodejs.org/dist/latest/ |
git branch -m old_branch new_branch # Rename branch locally | |
git push origin :old_branch # Delete the old branch | |
git push --set-upstream origin new_branch # Push the new branch, set local branch to track the new remote |
'use strict' | |
const EventEmitter = require('events').EventEmitter | |
const addon = require('bindings')('emit_from_cpp') | |
const emitter = new EventEmitter() | |
emitter.on('start', () => { | |
console.log('### START ...') | |
}) |
#include<napi.h> | |
#include <chrono> | |
#include <thread> | |
#include <iostream> | |
Napi::Value CallEmit(const Napi::CallbackInfo& info) { | |
Napi::Env env = info.Env(); | |
Napi::Function emit = info[0].As<Napi::Function>(); | |
emit.Call({Napi::String::New(env, "start")}); |
'use strict' | |
const EventEmitter = require('events').EventEmitter | |
const NativeEmitter = require('bindings')('native_emitter').NativeEmitter | |
const inherits = require('util').inherits | |
inherits(NativeEmitter, EventEmitter) | |
const emitter = new NativeEmitter() |
#include <chrono> | |
#include <thread> | |
#include <iostream> | |
#include "native-emitter.h" | |
Napi::FunctionReference NativeEmitter::constructor; | |
Napi::Object NativeEmitter::Init(Napi::Env env, Napi::Object exports) { | |
Napi::HandleScope scope(env); |