How to Polyfill node core modules in webpack 5

I was also getting these error’s when upgrading from webpack v4 to v5. Resolved by making the following changes to webpack.config.js added resolve.fallback property removed node property { resolve: { modules: […], fallback: { “fs”: false, “tls”: false, “net”: false, “path”: false, “zlib”: false, “http”: false, “https”: false, “stream”: false, “crypto”: false, “crypto-browserify”: require.resolve(‘crypto-browserify’), //if … Read more

Test process.env with Jest

The way I did it can be found in this Stack Overflow question. It is important to use resetModules before each test and then dynamically import the module inside the test: describe(‘environmental variables’, () => { const OLD_ENV = process.env; beforeEach(() => { jest.resetModules() // Most important – it clears the cache process.env = { …OLD_ENV … Read more

How to create full path with node’s fs.mkdirSync?

Update NodeJS version 10.12.0 has added a native support for both mkdir and mkdirSync to create a directory recursively with recursive: true option as the following: fs.mkdirSync(targetDir, { recursive: true }); And if you prefer fs Promises API, you can write fs.promises.mkdir(targetDir, { recursive: true }); Original Answer Create directories recursively if they do not … Read more

How to redirect 404 errors to a page in ExpressJS?

I found this example quite helpful: https://github.com/visionmedia/express/blob/master/examples/error-pages/index.js So, it is actually this part: // “app.router” positions our routes // above the middleware defined below, // this means that Express will attempt // to match & call routes _before_ continuing // on, at which point we assume it’s a 404 because // no route has handled … Read more

static files with express.js

If you have this setup /app /public/index.html /media Then this should get what you wanted var express = require(‘express’); //var server = express.createServer(); // express.createServer() is deprecated. var server = express(); // better instead server.configure(function(){ server.use(‘/media’, express.static(__dirname + ‘/media’)); server.use(express.static(__dirname + ‘/public’)); }); server.listen(3000); The trick is leaving this line as last fallback server.use(express.static(__dirname + … Read more

Why use peer dependencies in npm for plugins?

TL;DR: peerDependencies are for dependencies that are exposed to (and expected to be used by) the consuming code, as opposed to “private” dependencies that are not exposed, and are only an implementation detail. The problem peer dependencies solve NPM’s module system is hierarchical. One big advantage for simpler scenarios is that when you install an … Read more

Docker-compose: node_modules not present in a volume after npm install succeeds

This happens because you have added your worker directory as a volume to your docker-compose.yml, as the volume is not mounted during the build. When docker builds the image, the node_modules directory is created within the worker directory, and all the dependencies are installed there. Then on runtime the worker directory from outside docker is … Read more

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