How to Run and Submit Code, or Advice to Myself a Year Ago

Table of contents

No heading

No headings in the article.

Hi there,

I wanted to compile some information about things I personally struggled with a year or even several months ago. Some of them may seem obvious, and kudoz to you if you knew it, but honestly my life would have been much easier if someone shared it at that time. I tried to explain it as simple as possible. One last thought - if this list helps at least one person, I would consider my mission accomplished. So, let's start:

via GIPHY

When a JavaScript project is sent to you either by email, or you clone it from a repository, there are a few steps needed to get it running:

  1. Read its documentation. This is obvious, as I said, don't rush, open the README.md file and go through line by line. You may get many questions answered at this step. Typically this file contains steps with commands needed to install dependencies. All you need is just follow the steps and paste the commands in your terminal.

  2. Most likely it will start with npm install (or yarn) to add a folder with dependencies called node_modules to your project. Because of its heavy weight, the folder should be removed when you send the project back.

  3. If you want to upload your project to github, you don't need to remove the node_modules folder manually. Simply create a file called .ignore in the root of your project and then add a line containing node_modules to it. This will tell git to ignore the folder when pushing the code to the repository.

  4. To run your project you would typically need to use the command npm start or npm run start, which is just an extended version of the first.

  5. If you want to run a separate JavaScript file in your project, you can do it easily. You will need to go into the needed folder and then type node <filename.js> in your terminal. For example, node firstTask.js.

npm stands for Node Package Manager.
git is a version control software.
You will need to install them before all these steps, but I assume this is already done.

via GIPHY

Version control with git is a enormous topic, here are some small tips:

  1. If you have set up a completely new project, you will need to initiate an empty repository for it. To do this type git init.

  2. If you want to check whether there is a repository already existing you could type git status. In the output your may see information about changes in the code waiting to be submitted.

  3. To submit changes you need to stage them first, which means put them in the queue for sending to the remote repository. To do this you need either to type git add <filename> or directly in the source tree of your code editor. I mix both methods when using VS Code. The source tree may get glitchy and display the current information incorrectly, check in the terminal if you have any doubt.
    You can always unstage the changes. I usually use the minus button near the file name in the source tree interface.

  4. After staging you need to commit the changes. It's a good practice to add description of the changes made. Either type git commit -m <commit description> or use the source tree interface to enter the text and hit Submit after.

  5. One more step left - you need to submit the changes. Type git push or use the source tree interface to push the code to the repository. If it the very first commit, VS Code or any other tool you are using will ask you if you want to publish a branch, click Yes and your code should be submitted.

  6. If there are several people working on the same project, make it a rule to click Pull or type git pull before starting to code. This will pull the most recent changes and save you from lots of pain called merge conflict. If a merge conflict happens, stay calm and use your googling skills to resolve it, or better ask a more experienced person to help.

via GIPHY

VS Code tips to save your time

  1. To bring up a terminal in VS Code click Ctrl + J, no need to search for it in the tabs. Easy!

  2. To hide or show the file tree click Ctrl + B

  3. To open a search window, click Ctrl + F. To replace pieces of code, toggle the search window and fill out boxes with the Search and Replace labels.

  4. You can change the colour theme either by going into Code > Preferences > Color Theme or by clicking Ctrl + K + Ctrl + T.

Most importantly, you can do it, it takes only once to get it!