Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to place JS files for NodeJS to see them

Tags:

I've just installed NodeJS on my Mac, and i got it working in the terminal, using inline scripting like "console.log('Hello world'); works fine.

But where do i place JS files for NodeJS to find them? Can i specify the root folder NodeJS to look for file in?

I followed this guide: http://nodeguide.com/beginner.html#learning-javascript but i cannot get any of the samlpe to work where i reference a script file.

like image 587
Bødlen Avatar asked Dec 02 '11 16:12

Bødlen


People also ask

Where do I put node js files?

You put them in whatever folder you want. It is common practice to put each application in a different folder. Show activity on this post. You'll have to navigate to the correct folder "manually", in the Node Command Line Interface (CLI).

How do I view a .js file?

Right-click the file and select "Open With" and "Notepad." This will open Notepad with your JS file loaded. Since JS files are always written in plain text, Notepad is a suitable editor for the file. When you're finished editing, go to "File" and "Save" to save the file.

Where can I run a .js file?

You can Run your JavaScript File from your Terminal only if you have installed NodeJs runtime. If you have Installed it then Simply open the terminal and type “node FileName. js”. If you don't have NodeJs runtime environment then go to NodeJs Runtime Environment Download and Download it.


1 Answers

You put them in whatever folder you want. It is common practice to put each application in a different folder.

Then you run node.js like this:

node /path/to/file.js 

Or like this:

cd /path/to/ node file.js 

Where file.js might look something like this:

console.log('hello world'); 
like image 50
Alec Gorge Avatar answered Sep 27 '22 20:09

Alec Gorge