-1

I am a beginner in node js and have a couple of months experience with javascript, have finished codecademy js and jquery introductory courses and learned more about js in the internet and have an understanding of html and css in intermediate level or near to intermediate level. I am a complete noob in getting the js and node js to run alltogether. Using VS code for text editor. Node.js is installed from their original homepage, using node.js APP. File named global js.is sticked to 2 folders: the same with node.js and desktop folder for vs code files( the ones I create in VS code as projects or just simple files). The darn thing just doesn't make sense to me and I dont get this mess to work either. To be more specific, then:

I have 2 issues:

Firstly, did an install: npm install javascript bla bla. It was a sucsess, mkdir and cd were successful. NUL >introduction.js says access denied.

Alos I have a file named global.js. It is sitting in the same foler as node.js + the original version of this fie is in the same folder of desktop vs code's excercises. I can't make my node.js open this global.js file.

How do I overcome of these issues?

I tried to use this as a guide line: How to run a hello.js file in Node.js on windows?.

Did following parts of that above: changed account type to ADMINISTRATOR via appwize smth from run. Called cmd from run after having given myself and admin status permanently and windows logged me off and back on again. Tried to run the file from command prompt, declaring the exact path to file in cmd. It reached to the path, showed no error, went to the file from there. No errors, NOTHING didn't happen... Tried the global install whatever faced an issue in there and got stuck with it.

I need some help in here! Would be nice if someone could explain to me what is wrong and what's the basic concept of using node.js or what are the alternative ways to programmetely launch it?

Do I need to use the node.js console or node.js app?

CODE IN main. js :

var http = require("http");
var path= require ("path");
http.createServer(function (request, response) {
// Send the HTTP header 
// HTTP Status: 200 : OK
// Content Type: text/plain
response.writeHead(200, {'Content-Type': 'text/plain'});

// Send the response body as "Hello World"
response.end('Hello World\n');
}).listen(8081);

// Console will print the message
console.log('Server running at http://127.0.0.1:8081/');
console.log (`Rock on World from ${path.basename(__filename)}`);
var http = require("http");

http.createServer(function (request, response) {

// Send the HTTP header 
// HTTP Status: 200 : OK
// Content Type: text/plain
response.writeHead(200, {'Content-Type': 'text/plain'});

// Send the response body as "Hello World"
response.end('Hello World\n');
}).listen(8081);

// Console will print the message
console.log('Server running at http://127.0.0.1:8081/');
  • Please include a [MCVe](https://stackoverflow.com/help/mcve) in your question, including the lines where you get the "access denied", where you try to include your other file and how you call it. – Tobias K. Aug 19 '18 at 12:13
  • It was in cmd or in node.js app, npm install global javascript smth mkdir c:, cd command then command: NUL >introduction.js. Then access denied... – endrik2500 Aug 19 '18 at 14:56
  • I just wonder how can I get node to run the file, that was named global.js. I reneamed to main.js to prevent the machine from thinking like it was a some sort of global variable file. Node doesn't et me reach to it, even if it in the same folder as node.js and it's also duplicated in my desktop folder. I can't define to Path to my desktop: cmd order node; order: c:; order: Users response: ReferenceError: Users is not defined.... – endrik2500 Aug 19 '18 at 15:00

1 Answers1

0
  • No need to use any special console, on windows, standard cmd is enough.
  • Check if node is installed properly first. Run node -v and see if it prints its version.
  • Create a folder for your project and make sure your are in it before executing node or npm. Node.exe doesn't have to be in the project folder as long as it is in the path (by default it is)
  • Make sure your source files in that project folder. (test.js, introduction.js .. whatever you will run)
Bulent Vural
  • 2,630
  • 1
  • 13
  • 18
  • Tried with VS Code terminal, result: v8.11.4 ; node.cmd v8.11.4, command prompt also the same. Meaning now it works. I had issue with getting the version out of cmd. I needed to declare the PATH to somewhere in windows list of PATH's. seems that after that all the consoles seem to understand what node is. – endrik2500 Aug 19 '18 at 14:39
  • Ok, in VScode, terminal command main.js opening the main.js file in VScode. That's progress. Node terminal acting the same, when I am IN one of these 2 folders.... Now there is probably smth wrong in main js that I don't see the console logging anything. – endrik2500 Aug 19 '18 at 15:06