The vital files are:
package.json contains information about your program:
- Your program's name
- A brief description of your program
- Your name (so you can get credit for your work!)
- Other details that help the system run your program
Whereas the file above (package.json) is meant for you to record your project's details, this file (package-lock.json) is meant for the system to record details, based on what you define in package.json.
So you should never modify or remove package-lock.json. It's meant only for the system to read and modify. In fact, it's fine if you get in the habit of ignoring package-lock.json completely.
main.js is your program! It's the file into which you will write your code.
If you look at main.js now, you will see a line of code at the top of the file:
var ask = require('readline-sync');
var favorite_color = ask.question("What is your favorite color?")
That line of code will ask your user what their favorite color is. And it will store their reply inside of a "variable" named
(Asking users for their input is a pretty common, fundamental requirement when building programs. That's the only reason why we've included this line of code to start off. If you were building something that didn't need to ask users for their input, then this line would not be necessary.)
First, if you haven't already, you need to copy these files into a folder in your workspace.
You can do this with one easy click if you're using Cloud9. Just click this button:
Once you are able to access the files, open up package.json and add real information for your project's name, description, and your name. Don't forget to save! :)
2. Install System Tools
Next, run the following command in the terminal:
There are two things that will happen when you run
npm install, which you should ignore:
You might see some warnings like this:
npm WARN firstname.lastname@example.org No repository field. npm WARN email@example.com No license field.
These warnings are 100% okay, and it is safe to ignore them.
You might see a new folder called node_modules/ appear in your files. This is the folder where the system tools you just installed are stored. It is best to ignore this folder completely.
3. Start Program
To start your program, run the following command in the terminal:
This will run the main.js program. Since there's almost nothing in that file yet, this command doesn't do much of interest. But it should output some system messages like this:
> firstname.lastname@example.org start /username/project > node main.js
Your actual might be a little bit different, but essentially this is the system telling you that it received your instructions to start the program and is running the main.js file.
4. Have fun!
Now you can begin coding a program! Add your code to main.js and–after saving the file–run
npm start to see what your program does. Repeat this process until you're satisfied or have a question to ask.