CS304: Frequently Asked Questions

Whenever we discover something, solve a knotty bug, or come across anything else that is worth keeping around as a reminder, please let me know so that I can add it to this list.

Click on a question to toggle it

How do I copy files from my partner's account to my own?

You can't copy them from your partner, but your partner can drop the files to you. See this explanation for more detail, but the quick summary is that your partner should do:

      
tar cf dir.tar dir/
drop youracct dir.tar
and then you can go to your drop folder, untar them, and copy them to where you want them.
How do I run the Mongo Shell

The mongo command connects by default to a local Mongo server, not the one in the cloud. So we need to give it a URL that includes our username and password, both of which are stored in the ~/.cs304env.sh file. So, we have two ways to connect a Mongo Shell to the Mongo Cloud Atlas server:

  • Two steps using built-in Unix commands. The first step only needs to be done once per terminal:
    source ~/.cs304env.sh; mongo $MONGO_URI
  • One step using command in the course account:
    ~cs304node/public_html/bin/mongo-atlas
How do run my Node program?

It can be helpful to have a checklist. This works for me in the demo account, assuming it has the people_app that we discussed in class:

        cd ~/cs304/apps/people_app/
        node server.js
    

Then clicking on the link usually works.

How do I kill my node process?

Assuming that you're at the terminal (shell) that is running Node, you just type ^C (control-c). But you probably knew that.

So, this question only arises if you aren't at that terminal or have lost it. That means you have to determine the process ID (PID) of your flask process and kill that process. The PID is an arbitrary 4 or 5 digit number, and will be different every time you run Node.

I'll describe two approaches, one that uses a simple script that I have supplied, but which won't work on any other computer system, and a general approach that will expand your knowlege of Unix.

  • The simple way is to use the ~cs304node/public_html/bin/kill-my-node-process command. It wants a port number on the command line or the keyword id, in which case it'll use your id. Examples:
    ~cs304node/public_html/bin/kill-my-node-process id
    ~cs304node/public_html/bin/kill-my-node-process 1943        
    
  • The more general way is to use some Unix commands you probably don't know. Let's assume that the port that your node process is running on is 2345. You can find open network programs using the netstat command. You can use grep to filter that output to look for your port. That should, hopefully, print just the process PID that you need. Then, you can then kill the process with the kill command, giving the PID you learned from netstat and grep.

    Here's an example. You may have to scroll horizontally to see the PID information printed by netstat.

    $ netstat -ntlp | grep 2345
    (Not all processes could be identified, non-owned process info
     will not be shown, you would have to be root to see it all.)
    tcp        0      0 0.0.0.0:2345            0.0.0.0:*               LISTEN      56789/node
    $ kill 56789
    $ netstat -ntlp | grep 2345
    (Not all processes could be identified, non-owned process info
     will not be shown, you would have to be root to see it all.)
    

    Note that netstat won't tell you about processes you don't own, so it issues that warning every time. Don't worry about it.

How do I set up an SSH tunnel?

In a shell on my laptop (not logged into Tempest), I would type:

ssh -L 8000:localhost:1942 anderson@cs.wellesley.edu

Then, access localhost:8000 in the browser.

Notice that it uses port 8000, to avoid conflict with VS Code. Alternatively, forward your personal port number and access that in the browser, allowing VSCode to set up the forwarding for you.

Can I login to my CS account from off-campus?
Yes. The CS server is accessible globally. Just be sure to use the full name: cs.wellesley.edu. For example:
$ ssh cs304guest@cs.wellesley.edu
Can I access my Node app from off-campus?
Yes, but there's a trick. The campus firewall does not allow access to our "UID" ports from off-campus, but you can get inside the campus firewall in one of two ways:
  • Use the VPN software that LTS supports.
  • Use SSH Port Forwarding/Tunneling. For example, my Tempest UID (and hence my port) is 1492. On-campus, I would use a URL like http://cs.wellesley.edu:1942/. To set up an SSH tunnel, I would do the following.

    In a shell on my off-campus laptop, I would type:

    $ ssh -L 8080:localhost:1942 anderson@cs.wellesley.edu

    Once I login as anderson@cs.wellesley.edu, that sets up port 8080 on my laptop to forward port 1942 from cs.wellesley.edu. Obviously, you would substitute your own account and your own port.

    Then, in my laptop's browser, I go to localhost:8080/

    If you're a Windows user, you should use PuTTY. The following SSH on Windows article explains how to use PuTTY and how to set up an SSH tunnel using PuTTY.

The advantage of SSH tunnels over the VPN is slightly higher performance and, sometimes, easier setup, but the advantage is small, so use whichever you prefer. We must use the VPN when we use CAS.

Checklist for Viewing Node App from Off-Campus
  • set up the SSH tunnel in an ordinary terminal (or use the VPN)
  • In VS Code:
    1. login
    2. activate your venv
    3. navigate to your app
    4. run app.py (or the equivalent)
  • In a browser, go to localhost:8080
Where is the data in my request?
  • req.params if the data is in a parameterized endpoint
  • req.query if the data is in the query string (e.g. a form using the GET method)
  • req.body if the data is in the body (e.g. a form using the POST method)
  • req.cookies if the data is in a cookie (e.g. a form using the POST method), though in practice we would almost always use the session
  • req.session if the data is in the session
In the CRUD assignment, movies with multiple words in the title don't work. It only shows the first word.
The full title is probably there in the HTML. Do a "view source" and you will probably see them, but parsed as attributes of the input rather than the value. The template needs to surround a value with quotation marks.