Note to Self: Installing Node and NPM when i'm not at home
by Al Porotesano
The simple path to building a Node app at Home where Home is my Linux Terminal (or Mac terminal or Windows Command Prompt / Powershell).
Start with the Terminal:
me@dingdong:~$ the terminal syntax I should type
NVM or Node? You can do both, but it’s a headache
Yeah I could install both NVM and Nodejs, but it’s a headache to even try. If I install NVM, I can go to nodejs.org and see the stable version to work with. If I install nodejs, I’m just going to use the current version and forget I’ll have to update it later. Or maybe I can be content with the current version until it’s out of fashion.
Installing NVM
If you type nvm -v and nothing comes up, You’ll have to install it. It’s better to install it with the Terminal:
(I’m using Linux. Your Mac and Windows may vary)
sudo apt-get update
sudo apt-get install build-essential checkinstall
sudo apt-get install libssl-dev
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.0/install.sh | bash
restart terminal to boot nvmcommand -v nvm
nvm ls-remote
nvm install 4.4.7
nvm use 4.4.7
nvm alias default node
note: 4.4.7 is the current stable version when I wrote it on July 15, 2016
I guess that was easy. I can just use the Node Version Manager, choose a version, and I’m good to go.
Maybe it’s necessary to use sudo apt autoremove
if my terminal says so after I sudo apt-get install libssl-dev
to get rid of the useless libs in my machine.
Or maybe, I’m not necessarily thinking it’s that easy.
Maybe I do need to just install Node.js after all.
Installing Node.js
I’m on nodejs.org to download this thing thinking, “ok, someone thought of us noobs with a simple download, right! I’m gonna download this file, click install, and the computer is gonna do it all by itself for me.”
Nope. I’m in a directory of links saying to myself “what’s an x86?”, “What psychopath thought we’d understand 32-bit or 64-bit as if we know how to drive the difference between a Ford Taurus or a Toyota Camry?”
You’ll google for answers and you’ll think one is right. Or not. You’ll research for a million pages that have the same instructions:
sudo apt-get install nodejs
and then you’ll realize, “What version of node did I get?”
Before you turn into some dingdong banging your head to a wall or floor or sidewalk, Consider this easy approach for your workstation. Follow these steps.
getconf LONG_BIT
uname -p
If you use getconf LONG_BIT
, you should have the bit version appropriate for the nodejs package to download (32 or 64 bit)
If you use uname -p
, you should get the architecture version. x86_64 is for 64-bit processors. xi86 is for 32-bit processors. I know the 64-bit has more stuff to do.
Still in Terminal?
firefox
- http://www.nodejs.org
- click the left green button that has the words “Recommended for most users” above the version number.
- save it on your Download folder (People smarter than me know they can download it anywhere)
cd Download
ls Download
-
list of files in Download folder should show node-v4.4.7-linux-x86.tar.xz ( node v.4.4.7 was the latest version when I was writing this in July 2016 I updated post on March 2017 to reflect the current updates with node )
-
sudo apt-get install xz-utils
tar -C /usr/local --strip-components l -xjf node-v4.4.7-linux-x86.tar.xz
ls -l /usr/local/bin/node
ls -l /usr/local/bin/npm
instructions no. 6 and no. 7 should tell me I have both node and npm in my bin folders.
Installing NVM or Nodejs or both is fine. I prefer NVM for backward and forward compatibility of my stuff
Sweet. Now I know i’m not a ding-dong.
Now to my app project
Follow the steps if this is your first time:
node -v
npm -v
sudo apt install node-express-generator
express [name of project]
cd [name of project] && npm [name of project]
ls
[displays list of modules and .js files on project]node app
you should see: Express server listening on port 3000 in development modefirefox
type localhost:3000 on my url. test. dab. test. blah. done- Press Shift and C to exit localhost on terminal
If you’re going to do this continouously:
express [name of project]
cd [name of project] && npm [name of project]
node app
ornpm start
in my 32-bit workstation, I usenode app
because i’m a ding dong who forgot to add “start:somethingscript.coffee” on my package.json file. However, in my other workstationnpm start
just defaults the launch from server.js. I’m guessing because I haven’t changed my package.json scripts yet unless I have to.firefox
enter localhost:3000
Not sure what IDE app you use to write your project, but VS Code is great because it’s free and i’m poor.
- Al Porotesano