This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
// 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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: { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# make soure you have mocha installed | |
npm i mocha -g | |
# run tests with mocha | |
mocha --reporter=spec test.spec.js |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* @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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* A custom MyError class | |
* @class | |
*/ | |
class MyError extends Error { | |
/** | |
* Constructs the MyError class | |
* @param {String} message an error message | |
* @constructor | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* A custom MyError class | |
* @class | |
*/ | |
class MyError extends Error { | |
/** | |
* Constructs the MyError class | |
* @param {String} message an error message | |
* @constructor | |
*/ |
OlderNewer