npm command to uninstall or prune unused packages in Node.js

Note: Recent npm versions do this automatically when running npm install if package-locks are enabled, so this is not necessary except for removing development packages with the –production flag. Run npm prune to remove modules not listed in package.json. From npm help prune: This command removes “extraneous” packages. If a package name is provided, then … Read more

The difference between “require(x)” and “import x”

This simple diagram will help to you understand the differences between require and import. Apart from that, You can’t selectively load only the pieces you need with require but with import, you can selectively load only the pieces you need, which can save memory. Loading is synchronous(step by step) for require on the other hand … Read more

What is Express.js? [closed]

1) What is Express.js? Express.js is a Node.js framework. It’s the most popular framework as of now (the most starred on NPM). . It’s built around configuration and granular simplicity of Connect middleware. Some people compare Express.js to Ruby Sinatra vs. the bulky and opinionated Ruby on Rails. 2) What is the purpose of it … Read more

Setting Environment Variables for Node to retrieve

Environment variables (in this case) are being used to pass credentials to your application. USER_ID and USER_KEY can both be accessed from process.env.USER_ID and process.env.USER_KEY respectively. You don’t need to edit them, just access their contents. It looks like they are simply giving you the choice between loading your USER_ID and USER_KEY from either process.env … Read more

How do I override nested NPM dependency versions?

You can use npm shrinkwrap functionality, in order to override any dependency or sub-dependency. I’ve just done this in a grunt project of ours. We needed a newer version of connect, since 2.7.3. was causing trouble for us. So I created a file named npm-shrinkwrap.json: { “dependencies”: { “grunt-contrib-connect”: { “version”: “0.3.0”, “from”: “grunt-contrib-connect@0.3.0”, “dependencies”: … Read more

Node.js check if path is file or directory

The following should tell you. From the docs: fs.lstatSync(path_string).isDirectory() Objects returned from fs.stat() and fs.lstat() are of this type. stats.isFile() stats.isDirectory() stats.isBlockDevice() stats.isCharacterDevice() stats.isSymbolicLink() // (only valid with fs.lstat()) stats.isFIFO() stats.isSocket() NOTE: The above solution will throw an Error if; for ex, the file or directory doesn’t exist. If you want a true or false … Read more

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