My Guide to Adding Node.JS to My Project

My Challenge

To remind myself for all eternity how to add node.js to a project that will live remotely on a server, and not able to access the version of node.js that’s on my local computer.

What is node.js?

Node allows JavaScript, originally a client-side programming language processed in the browser, to be used as a server-side language.

Why do I need it for my project?

I want to run a little server to handle visitors’ requests to my website, and I want to write it in Javascript. Node.js will allow my javascript server to perform this “server-side” functionality.

I also need node.js inside my local project because it’s going to live on a remote server, without access to my globally installed node.js on my computer.

How do I add Node.js to a local project?

I’ll use npm (or “node packaged models”) as a tool to install node.js into my local project. npm can install the node.js packages I need in local or global mode. In local mode it will install packages in a node_modules folder in my project’s parent working directory.

Use this npm webpage to find the latest commands.

But generally all I need to do is inside my project’s working directory in terminal, use $ npm install node.js ($ npm install <package_name>).

One extra step

Then put the created package.json file and node_modules folder onto my remote server, so that my html and javascript files have access to them. I do this by opening up the application Fetch, and dropping in the files.

How do I check for updates?

Check NPM’s webpage here for the latest commands. Generally, first check that I have node and npm installed. To check if you have Node.js installed, run this command in your terminal.

Note: This command checks whether node.js exists globally on your machine, not whether a copy is saved in your project folder that will exist on a remote server. I need both.

node -v

To confirm that you have npm installed you can run this command in your terminal:

npm -v

npm is a separate project and updates more regularly, so update your npm. To update your npm, type this into your terminal:

npm install npm@latest -g

How do I make sure I’m using a LTS version of Node.js ?

Not sure yet.

Should I use a Node.js version manager?


Is there a way to switch between versions of node and npm?


How do I switch my project over to run forever?

Full instructions here.

Type $ npm install forever -g

Then type forever start app.js