Skip to content

Instantly share code, notes, and snippets.

View mrister's full-sized avatar
🏠
Working from home

Mihovil Rister mrister

🏠
Working from home
View GitHub Profile
@mrister
mrister / nodemon.sh
Last active June 8, 2016 08:30
nodemon example
#!/usr/bin/env bash
# first, install nodemon from npm
npm install -g nodemon
# use nodemon to monitor your app.js by running the following command from your project directory.
nodemon app.js
# Or use nodemon in verbose mode and start the server.
# Watch app and lib directories and ignore tests and .spec.js named files in lib directory.
# Only detect changes on files with js extensions (-e).
@mrister
mrister / forever-config.json
Last active November 16, 2023 16:24
Forever example with config file
{
// Sample configuration for app in /home/myuser/app dir
"uid": "app",
"max": 5, // restart the app successively maximum of 5 times
"spinSleepTime": 1000, // time to wait until a next restart is attempted (in ms)
"append": true, // append the logs, do not overwrite
"watch": true, // watch for changes and restart if they occur
"script": "server.js", // main startup script (almost like issuing node server.js)
"sourceDir": "/home/myuser/app", // the dir where your entire app code resides (dir structure is recursively traversed)
"args": ["--myAPIKey", "xBlzdn84fa"] // pass any arguments to your app
@mrister
mrister / pms-development.sh
Last active April 6, 2019 19:06
pm2 example
#!/usr/bin/env bash
#install pm2
npm i pm2
#run with process.json configuration file for development environment
pm2 start process.json --env development
# delete it all
# pm2 delete process.json
@mrister
mrister / newrelic.js
Last active May 11, 2017 06:44
New Relic example
/**
* New Relic agent configuration.
*
* See lib/config.defaults.js in the agent distribution for a more complete
* description of configuration variables and their potential values.
*/
exports.config = {
app_name: ['my application'],
license_key: '<licenese key>', // only thing required (or set NEW_RELIC_LICENSE_KEY env variable)
logging: {
@mrister
mrister / runt_test.sh
Last active July 1, 2021 10:30
Mocha and chai example
#!/usr/bin/env bash
# make soure you have mocha installed
npm i mocha -g
# run tests with mocha
mocha --reporter=spec test.spec.js
@mrister
mrister / babel_transpile.sh
Last active June 8, 2016 08:21
Babel example
#!/usr/bin/env bash
# install babel cli and preset
npm install --save-dev babel-cli babel-preset-es2015
# do the transpiling of original.js file to transpiled.js
babel original.js --out-file=transpiled.js
@mrister
mrister / es5-custom-node-error.js
Last active February 18, 2020 17:30
A custom Node.js error example of ES5
/**
*
* @param {String } name is the name of the newly created error
* @param {Function} [init] optional initialization function
* @returns {Err} The new Error
*/
function createError(name, init) {
function Err(message) {
Error.captureStackTrace(this, this.constructor);
this.message = message;
@mrister
mrister / simple-node-es5-error.js
Last active December 25, 2018 09:35
A simple custom Node.js error
/**
* A custom MyError
* @param {String} message a message to store in error
* @constructor
*/
function MyError(message) {
this.constructor.prototype.__proto__ = Error.prototype;
// properly capture stack trace in Node.js
Error.captureStackTrace(this, this.constructor);
this.name = this.constructor.name;
@mrister
mrister / simple-custom-nodejs-es6-error.js
Created August 5, 2016 11:10
A simple custom Node.js ES6 Error
/**
* A custom MyError class
* @class
*/
class MyError extends Error {
/**
* Constructs the MyError class
* @param {String} message an error message
* @constructor
*/
@mrister
mrister / custom-es6-node-error
Last active July 13, 2017 07:21
A custom Node.js ES6 error.
/**
* A custom MyError class
* @class
*/
class MyError extends Error {
/**
* Constructs the MyError class
* @param {String} message an error message
* @constructor
*/