Dynamically add version number to dest output files w/ grunt

I implemented: https://github.com/erickrdch/grunt-string-replace In my source css/js files, I use the text {{ VERSION }} which gets replaced with the version number set in the package.json file. Below is the config I added to Gruntfile.js. ‘string-replace’: { version: { files: { // the files I did string replacement on }, options: { replacements: [{ pattern: … Read more

Modify existing Excel File using node.js

exceljs does let you modify Excel spreadsheets. Here’s an example of reading in an existing spreadsheet and writing it back out to a different file: var Excel = require(‘exceljs’); var workbook = new Excel.Workbook(); workbook.xlsx.readFile(‘old.xlsx’) .then(function() { var worksheet = workbook.getWorksheet(1); var row = worksheet.getRow(5); row.getCell(1).value = 5; // A5’s value set to 5 row.commit(); … Read more

How to use GridFS to store images using Node.js and Mongoose

I was not satisfied with the highest rated answer here and so I’m providing a new one: I ended up using the node module ‘gridfs-stream’ (great documentation there!) which can be installed via npm. With it, and in combination with mongoose, it could look like this: var fs = require(‘fs’); var mongoose = require(“mongoose”); var … Read more

Nodejs EJS helper functions?

Yes, in Express 3 you can add helpers to app.locals. Ex: app.locals.somevar = “hello world”; app.locals.someHelper = function(name) { return (“hello ” + name); } These would be accessible inside your views like this: <% somevar %> <% someHelper(‘world’) %> Note: Express 2.5 did helpers differently.

ES6 filter an array with Regex

Firstly new RegExp(‘/\bcontact\b’, ‘g’); is equivalent to /\/@contact@/g where the @ are backspace character (ASCII 08) … clearly not what you want So, you would do new RegExp(‘/\\bcontact\\b’, ‘g’); – this is equivalent to /\/\bcontact\b/g However, the \\b after / is redundant so … down to /\/contact\b/g Using string.match here as regex.test is misused. Below … Read more

Connecting to remote SSH server (via Node.js/html5 console)

This is easily doable with modules like ssh2, xterm, and socket.io. Here’s an example: npm install ssh2 xterm socket.io Create index.html: <html> <head> <title>SSH Terminal</title> <link rel=”stylesheet” href=”https://stackoverflow.com/src/xterm.css” /> <script src=”/src/xterm.js”></script> <script src=”/addons/fit/fit.js”></script> <script src=”/socket.io/socket.io.js”></script> <script> window.addEventListener(‘load’, function() { var terminalContainer = document.getElementById(‘terminal-container’); var term = new Terminal({ cursorBlink: true }); term.open(terminalContainer); term.fit(); var socket … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)