node.js interview questions
Top node.js frequently asked interview questions
I have Windows 7 32-bit. I installed the latest Node.js 32 bit. When I try to run the command npm install jquery
, I receive the error:
Error: ENOENT, stat 'C:\Users\RT\AppData\Roaming\npm
How does one resolve it?
Source: (StackOverflow)
Despite knowing JavaScript quite well, I'm confused what exactly these three projects in Node.js ecosystem do. Is it something like Rails' Rack? Can someone please explain?
Source: (StackOverflow)
Are there any good resources to get started with Node.JS? Any good tutorials, blogs or books?
Of course, I have visited its official website http://nodejs.org/, but I didn't think the documentation they have is a good starting point.
Source: (StackOverflow)
How do I debug a Node.js server application?
Right now I'm mostly using alert debugging with print statements like this:
sys.puts(sys.inspect(someVariable));
There must be a better way to debug. I know that Google Chrome has a command-line debugger. Is this debugger available for Node.js as well?
Source: (StackOverflow)
I've been trying to find a way to write to a file when using Node.js, but with no success. How can I do that?
Source: (StackOverflow)
This documentation answers my question very poorly. I didn't understand those explanations. Can someone say in simpler words? Maybe with examples if it's hard to choose simple words?
EDIT also added peerDependencies
, which is closely related and might cause confusion.
Source: (StackOverflow)
What is the purpose of Node.js module.exports and how do you use it?
I can't seem to find any information on this, but it appears to be a rather important part of Node.js as I often see it in source code.
According to the Node.js documentation:
module
A reference to the current
module
. In particular module.exports
is the same as the exports object. See
src/node.js
for more information.
But this doesn't really help.
What exactly does module.exports
do, and what would a simple example be?
Source: (StackOverflow)
I just installed node and npm through the package on nodejs.org and whenever I try to search or install something with npm it throws the following error, unless I sudo the command. I have a feeling this is a permissions issue? I am already the admin.
npm ERR! Error: EACCES, open '/Users/chietala/.npm/-/all/.cache.json'
npm ERR! { [Error: EACCES, open '/Users/chietala/.npm/-/all/.cache.json']
npm ERR! errno: 3,
npm ERR! code: 'EACCES',
npm ERR! path: '/Users/chietala/.npm/-/all/.cache.json' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! System Darwin 12.2.0
npm ERR! command "node" "/usr/local/bin/npm" "search" "bower"
npm ERR! cwd /Users/chietala
npm ERR! node -v v0.10.4
npm ERR! npm -v 1.2.18
npm ERR! path /Users/chietala/.npm/-/all/.cache.json
npm ERR! code EACCES
npm ERR! errno 3
npm ERR! stack Error: EACCES, open '/Users/chietala/.npm/-/all/.cache.json'
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /Users/chietala/npm-debug.log
npm ERR! not ok code 0
Source: (StackOverflow)
After I upgraded to latest stable node
and npm
, I tried npm install moment --save
. It saves the entry in the package.json with the caret(^)
prefix. Previously, it was a tilde(~)
prefix.
- Why are these changes made in npm?
- What is the difference between tilde(~) and caret(^)?
- What is the advantages over others?
Source: (StackOverflow)
How should I parse JSON using Node.js? Is there some module which will validate and parse JSON securely?
Source: (StackOverflow)
How to find the version of an installed node.js/npm package?
This prints the version of npm itself:
npm -v <package-name>
This prints a cryptic error:
npm version <package-name>
This prints the package version on the registry (i.e. the latest version available):
npm view <package-name> version
How do I get the installed version?
Source: (StackOverflow)