I am new to using
nodejs completely, and it seems to be pretty much the go to thing for everything right now. But I program in Visual Studio, and I'm a bit confused about how this works. I will cite an example;
One task I want to do is to get a list of all the files in a directory and all of its sub-directories, and return them as a
.config file. I started searching for that and found a lot of answers, but they all kept going back to
nodejs, for instance, this one, and this one, and this one.
I really wasn't looking for anything having to do with
nodejs, it just seems to be part of every solution out there. I've installed it, and gotten it to where I can do some simple things like create a very basic server that listens to a port - thanks to simple tutorials written for a moron like me - but I'm having a hard time figuring out how to use these kinds of things in my real programs - specifically
ASP.NET MVC. I've searched pretty hard on this topic too, and discovered things like
iisnode and the like that do some partial integration.
But even with all of this, this wealth of information, I am extremely confused.
I understand that I can use it from a command line, like
PowerShell, I can run commands from a terminal, and install packages into projects, but I'm having a hard time seeing and finding how this actually translates into literal, real usage in an existing application. I have scoured around for days and days for examples, I've read at least 3 books on nodejs, The Node Beginner Book, What is Node, and Professional Node.js and to be very honest I am still as lost as ever.
Everything I read keeps assuming I am doing things from the command line or a terminal, but all of the applications I see for node assume you're writing a web application. I'm having a really hard time wrapping my head around how you use it within an application. Can anyone assist me with this? Perhaps a working example of an actual program that uses node? I'll take almost anything at this point, though
ASP.NET MVC is my core system of choice.
I was originally going to post this on
StackOverflow, but someone suggested that this community was more appropriate for this question.
I want to make a more clear example of what is confusing me, I'm already learning because of the 1 proposed answer, but let me give more examples.
I program in
Visual Studio, it has no real concept of
node.js - in fact, if I try to do things that will run against node, it gives me problems. I often have to code anything related to node in
I understand that I can 'compile' things with node, what I don't understand is how I can invoke it within my program, not inside of a command line. For example let's say there is a node module that takes an array and does something to it - for sake of example let's say that it sorts everything in the array alphabetically, and it is a module called supersort.
So if I were at the console, I would just type in ...
Okay, but now I'm not at the command line. I have published my web application. My user is at a page, let's say
/account/history and they are seeing a list of every product they have bought. For the sake of argument, say I've got that list as a
string - I realize that is completely absurd and it would be far more complex, but just jive with me.
I want to run
IIS? I think you can start to see where I am lost.
Attempting to further emphasize my question, I'll try and cite a more specific example. I want to use the library
Q.js in my
ASP.NET MVC application. Now, there is a version 1 that I can seem to run out of the box, but I want to try out version 2 - you can find it linked Q.js v2 (beta)
So I am using Visual Studio, and I'll download the
q.js file and load it up, but immediately we already have trouble now - if you look at the file's source code right away I see this.
require("collections/shim"); var WeakMap = require("collections/weak-map"); var Iterator = require("collections/iterator"); var asap = require("asap");
Now I certainly don't have folders with those names in my application - and even though I have
node.js installed, putting this file in a
<script> tag does not work, as it says it cannot find the specific libraries. If I go to a console explicitly and type in
npm install -g q@~2, it will create a folder called
node_modules/q in my
AppData/Roaming/npm folder, and this one does have folders for those other libraries.