Error trying when starting npm in m220js course in on Mongo University

I am trying to start the M220JS course. I downloaded the file and unzipped into my working dir, im using Ubuntu 20.04. I did the following things:

  1. I edited the dotenv_unix by adding a unique secret key as per the course instructions,
  2. the MFLIX_DB_URI with my mongo srv connection string from the 'connect your application, replacing the username, password and myFirstDatabase as per the instructions in the Atlas connection window.
  3. I renamed dotenv_unix to .env

When I run npm start i get the following error:
import app from “./server”;
SyntaxError: Cannot use import statement outside a module

After looking on stackoverflow, I see this is because type:module needs to be added to the package.json. When I do that I get
ReferenceError: require is not defined in ES module scope, you can use import instead

Again checking stackoverflow, it suggests changing type to commonjs to fix this error, but I get the first error then. I have tried doing this with multiple versions of node, (10.20.0 and 16.13.0).

Can anyone advise how to fix this, I have just started the course and so this is very frustrating.

You have been very detailed about everything that you did. But I do not see anything about running npm install.

Thanks for the reply, yes I did this but I continue to get the same error

I have it working now, for anyone else who is experiencing similar issues here is what worked for me, it has taken a while to get this going and is very frustrating, it would be very helpful if these stepped were outlined in the main course:

  1. Download the Zip file and extract into a directory of your choice, it will put a folder called mflix-js in this folder. Keep everything in this folder, I had at one point moved the contents to another folder which I was going to use but this prevented it from working.
  2. Go into the mflix-js folder with a terminal and download node version manager, for linux this can be done with (this is assuming you have node and npm installed already) :
    npm install nvm
    For windows you need to use nvm for windows (see this stackoverflow page), I am not sure about mac.
  3. Use nvm to use an older version of node, using 10.12.0 works for me, to install this and use it you can use (on linux, I am not sure about other OS)
    nvm install 10.12.0
    nvm use 10.12.0
    And check you are using this version now with:
    node -v
  4. Edit the dotenv_unix file as per the course instructions and save to .env and then use
    npm install
    npm start

Running npm start and testing the connection with npm test -t db-connection now both work for me. I hope this helps someone else.