Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Node.js Basics (2014) Building a Command Line Application Preparation and Planning

Bryan Davidson
Bryan Davidson
4,563 Points

Run node locally

I'm going through the node.js tutorial but I would like to do it on a local node installation rather than workspaces. I've installed node with no problem. but how do I create the app.js file?

3 Answers

Norman G
Norman G
4,658 Points

Just create the app.js file in your working directory and start the node server with node app.js

wait how do you create the app.js file? is it node new app.js?

edit: I figured it out, I just saved a file called app.js using sublime text editor.

J. MORENO
J. MORENO
12,550 Points

To clarify a bit in case someone has this same question:

Create File:

  1. You can do this through the console or use any text editor

console - Search online for commands for your system - Windows - Mac/Linux

Text Editor or IDE (Integrated Development Environment: https://en.wikipedia.org/wiki/Integrated_development_environment)

In a text editor or IDE - save any text file as a javascript file as in app.js or index.js - the same way you would create other file types, such as index.html. SAVE AS: anyjsfilename.js

Maybe save in a folder on your desktop of your device for easy access.

EXAMPLE:

LOCATION: desktop FOLDER NAME: nodeproject FILENAME CONTAINED IN FOLDER: app.js

  1. RUNNING FILE IN NODE:

    --2a Locate FIle

    example:

    in the console:

    cd desktop/nodeproject/ [press enter]

--2b Running File In Node

  node app.js [press enter]

Maybe overkill but I hope this helps.

Here are some good blogs that show you how to run NodeJS locally. Here is the link for if you are using a Mac: http://blog.ijasoneverett.com/2013/03/getting-started-with-node-js-on-mac-os-x/ and here is the link for Windows: http://blog.gvm-it.eu/post/20404719601/getting-started-with-nodejs-on-windows. These blogs explained how to do it so well that I wanted to make sure I shared them for any other people who run into this problem. If you are using GitBash like me, these are the steps you need to take to start the process of running node. First, type in "node -v" when you open Gitbash and you will get a response that will tell you the version you had installed. Then, you type in "npm -v" and that will give you the version that is running. Once that is done, follow the steps in the above links and you should be good to go. I hope this helps.