5

I'm not familiar with Ubuntu. I want to make some nodejs apps for testing, now I'm confused where I should create a directory for it.

I have searched in google and I found every one saying

sudo apt-get install nodejs npm

and create server.js file and put this code blah blah and run npm server.js etc.

But where I should create this file? Where I should create directory?

I know about /var/www/html but there are my other php projects here.

4 Answers 4

4

For development use a subdirectory if your user home dir.

E.g., ~/projects/test-project like somebody suggested.

You would usually add this to git, too. E.g.

mkdir -p ~/projects/test-project
cd ~/projects/test-project
# add your server.js now
git init
git add .
git commit -a -m 'here goes nothing'

For testing, you might wanna do something closer to what your deployment site looks like. Usually it's /srv/project-name or /var like you've suggested.

Those directories usually don't exist and you cannot access them by default, so you create them with sudo. Example:

sudo mkdir -p /srv/my-project
sudo chown `whoami`:`whoami` /srv/my-project
cd /srv/my-project
git clone ~/projects/test-project .

Now you can test both local dev version and the test one.

P.S. You should try nvm.sh for installing node, much more versions and fresher ones.

Sign up to request clarification or add additional context in comments.

1 Comment

Perfect, fully detailed answer, this is what I was looking. :)
3

You can place the projects anywhere you like. I usually put them in ~/projects.

Running npm start will fire up a web server running at http://localhost:8080, so there's no need for /var/www if you're just doing some testing.

Comments

1

To avoid permission issue, put the file in your Document folder. You can run the npm command from this folder. Fore expl create a folder "nodejs" inside your Document Folder and put your code here.

Comments

1

You can create a project directory anywhere in ubuntu (where you have permissions). For example home directory or your desktop. cd into this directory and create a server.js file that contains your code.

You can either use the node server or http-server module to serve your application. Link to the http-server module http-server

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.