Setup Node/Express/Git on ubuntu

To install Node.js, open a terminal and type the following command:


curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash –
sudo apt-get install -y nodejs

and then use n or nvm module to manage version.

Update: You should uninstall older version before installing newer version


sudo apt-get purge nodejs
sudo apt-get autoremove

Create a symbolic link for “node” as many Node.js tools use this name to execute.
/usr/bin/node is an executable:


ubuntu@VM-0-7-ubuntu:/usr/bin$ file node
node: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.18, BuildID[sha1]=7ecea95928ab854a79f9e5ca6d4b22df939620f6, not stripped

Hence, we want to create a symbolic link to our node executable like so:

sudo ln -s /usr/bin/nodejs /usr/bin/node

Now we should have both the node and npm commands working:

$ node -v
v0.10.25
$ npm -v
1.3.10

Install Express.js

Installing

Assuming you’ve already installed Node.js, create a directory to hold your application, and make that your working directory.

$ mkdir myapp
$ cd myapp

Use the npm init command to create a package.json file for your application. For more information on how package.json works, see Specifics of npm’s package.json handling.

$ npm init

This command will prompt your for a number of things such as the name and version of of your application. For now, you can simply hit RETURN to accept the defaults for most of them, except for:

entry point: (index.js)

Enter app.js or whatever you want the name of the main file to be. If you want it to be index.js, hit RETURN to accept the suggested default file name.

Now install Express in the app directory and save it in the dependencies list:

$ npm install express –save

To install Express temporarily, and not add it to the dependencies list, omit the –save option:

$ npm install express

installing mongoose

npm install mongoose –save-dev