Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where I should create a directory for nodejs apps?

Tags:

node.js

ubuntu

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.

like image 540
Muhammad Shahzad Avatar asked Feb 08 '23 08:02

Muhammad Shahzad


2 Answers

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.

like image 158
Zlatko Avatar answered Feb 09 '23 22:02

Zlatko


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.

like image 36
shoegazerpt Avatar answered Feb 09 '23 20:02

shoegazerpt