Author Archive
Node.js – Error: Module version mismatch. Expected 48, got 46.
Hello all,
This error is generated by the fact that you just upgraded a your major Node.js version, which is good, and your node_modules need to be re-installed.
I suggest you to run in your terminal rm -rf node_modules && npm install
to re-install all the dependencies.
Have a good day!
electron-package spawn wine ENOENT error on MacOS
Packaging app for platform win32 ia32 using electron v0.37.7 spawn wine ENOENT
This error is thrown because Electron tries to modify the .exe of the application using Wine, to add the icon you specified.
The spawn wine ENOENT
error means you don’t have wine installed.
Follow this guide to install and configure Wine correctly.
`sudo gem install` fails with ERROR: While executing gem … (Errno::EPERM)
Hello all,
To solve this:
1. Run nano ~/.gemrc
in your terminal.
2. Add the following line gem: -n/usr/local/bin
to the empty file. (CMD + V)
3. Save (CTRL + 0) and quit (CTRL + X)
Try again installing your gem 🙂
How to load a JSON content inside a js module with Webpack
Hello all,
At first Webpack can give you an hard time but after that, it’s all sugar!
Imagine you need to include a JSON file used for configuration in your `example.js` file:
1. Install the loader module json-loader
:
npm install json-loader --save-dev
2. Add the loader to your webpack.config.js
file:
loaders: [
{ test: /\.json$/, loader: 'json' },
// other loaders
]
3. Add in your `example.js` file the following line:
import config from '../config.json';
…and your JSON is ready to be used in your code, already parsed into a sweet object.
Cool, isn’t it?
What Webpack does being the scenes is converting the JSON file into a JS module and adding it to your build result:
/* some-webpack-require-number */
/***/ function(module, exports) {
module.exports = {
// your json content
}
}
var config = __webpack_require__(some-webpack-require-number);
Hosting multiple websites on the same node.js server
Hello all,
As basic as it can be, I made a little boilerplate to show the solution I used to host different websites with different domains on the same Node.js server on Openshift.
Assume that we have different domain and subdomains that should be redirect to the proper static websites folder.
The minimum configuration we need is described by only two attributes: the domain and the folder path.
First declare a JSON named `vhosts.json` with your environments information:
[
{
"domain": "www.example.com",
"path": "public/example_com"
},
{
"domain": "subdomain.example.com",
"path": "public/subdomain_example_com"
},
{
"domain": "my.website.com",
"path": "public/my_website_com"
}
]
Then create a `server.js` with the following contents:
var fs = require('fs'),
path = require('path'),
express = require('express'), // npm install express --save
vhost = require('vhost'); // npm install vhost --save
// Global application declaration
var app = express();
// Shared routes
app.get('/health', function(req, res) {
res.writeHead(200);
res.end();
});
// Virtual hosts
var virtualHosts = JSON.parse(fs.readFileSync('vhosts.json', 'utf8'));
virtualHosts.forEach(function(virtualHost) {
var virtualHostApp = express();
virtualHostApp.use(express.static(path.join(__dirname, virtualHost.path)));
app.use(vhost(virtualHost.domain, virtualHostApp));
});
// Listen on port 8080
app.listen(8080);
With just these 20 lines of codes our Node.js instance will be ready to server our static websites.
A different approach should be taken if we want to consider each website as a dynamic express application. In that case you should `require` all the children express applications in the `server.js` file and pass them to `vhost`.
That’s all, really!
You can find this boilerplate on this Github repository.
Have an express day!
Node, Sequelize and Promises: return the whole catalog / multiple queries at once
Hello all,
I wanted to share this god-like piece of pure beauty.
Hedonists will understand…
Automatic first available port selection applied to gulp livereload on node.js
Hello all,
During work I needed to take in consideration multiple instances of gulp w/ livereload.
Normally Gulp starts livereload on port 35729 and doesn’t auto-select the first available automatically.
This case can also be applied to any Node.js script that requires finding the first available port.
Ruby gem install sass: Operation not permitted
Hello,
Are you trying to install sass or other gems and your OS X El Crappytan is giving your troubles?
sudo gem install sass
ERROR: While executing gem ... (Errno::EPERM)
Operation not permitted - /usr/bin/sass
simply run sudo gem install -n /usr/local/bin sass
and that’s fixed.
Of course it works with any other gem that encounter this problem.
Have a good day!
Error: Cannot resolve module ‘style’ in webpack
Hello,
Module not found: Error: Cannot resolve module 'style' in
...
...
You probably have a require("!style!css!./css/style.css");
somewhere in your javascript files and webpack doesn’t find the style-loader
plugin.
To solve this run
npm install --save-dev style-loader