EzDevInfo.com

node.js interview questions

Top node.js frequently asked interview questions

Node.js/Windows error: ENOENT, stat 'C:\Users\RT\AppData\Roaming\npm'

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)

What is Node.js' Connect, Express and "middleware"?

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)

Advertisements

How do I get started with Node.js

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 Node.js applications?

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)

Writing files in Node.js

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)

How to read environment variable in Node.js

Is there a way I can read environment variables in Node.js code?

Like for example Python's os.environ['HOME'].


Source: (StackOverflow)

How to exit in Node.js

What is the command that is used to exit?


Source: (StackOverflow)

What's the difference between dependencies, devDependencies and peerDependencies in npm package.json file?

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?

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)

NPM throws error without sudo

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)

Difference between tilde(~) and caret(^) in package.json

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.

  1. Why are these changes made in npm?
  2. What is the difference between tilde(~) and caret(^)?
  3. What is the advantages over others?

Source: (StackOverflow)

Can I use jQuery with Node.js?

Is it possible to use jQuery selectors/DOM manipulation on the server-side using Node.js?


Source: (StackOverflow)

How can I update Node.js and NPM to the next versions?

I just installed Node.js and NPM (for additional modules).

How can I update Node.js and the modules I'm using to the last versions?

Can NPM do it? or do I have to remove and reinstall Node.js and NPM to get the next versions?

I followed https://github.com/joyent/node/wiki/Installation (step 3a) and the next NPM section.


Source: (StackOverflow)

How to parse JSON using Node.js?

How should I parse JSON using Node.js? Is there some module which will validate and parse JSON securely?


Source: (StackOverflow)

Find the version of an installed npm package

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)