Setting up Truman locally
The following steps will guide you through how to set up your own version of The Truman Platform. At the end, you should have a running version of the project on your local computer.
Below is a brief overview of the steps you will take to set up Truman locally:
The instructions for each step are outlined below.
Creating a MongoDB database instance
The Truman Platform uses MongoDB as its database system. It is where participant data, simulation data, and more is stored.
MongoDB Atlas is a managed cloud database service that hosts MongoDB databases. We will be using MongoDB Atlas to easily set up a free MongoDB database.
Step 1: Create an account on MongoDB Atlas
Click the green Try Free button in the top right of the header.
Sign up for an account by filling in your new account information and then clicking the Create your Atlas account button. After verifying your account, sign into your new account.
Upon signing in, you should be directed to the Database Deployments page.
Step 2: Create a MongoDB database
Click the green Build a Database button. You will be redirected to a selection page.
Choose the free database available.
Choose AWS as the provider.
Choose a region within the United States (ex: 'N. Virginia (us-east-1)').
Give your Cluster a name (ex: 'truman'; the default is 'Cluster0').
You do not need to change any of the other selected default options.
Click on the green Create button.
Wait for a while as your cluster is created (might take 5-8 minutes).
After the cluster is created, you will be redirected to the Security Quickstart page. Instead of defining Database Access and Network Access here, we will do it another way.
First, create a new MongoDB user.
Navigate to Security > Database Access via the left navigation panel.
Click the green Add a New Database User button.
Choose the authentication method: Password.
Under Password Authentication, create a username and password for the MongoDB User. You will need to remember both of these values.
Under Database User Privileges, choose the built in role: Atlas Admin.
You do not need to complete or select anything else. Click the green Add User button.
Afterwards, you will set up Network Access to your database.
Navigate to Security > Network Access via the left navigation panel.
Click the green Add IP Address button.
Click Allow Access from Anywhere. This will add 0.0.0.0/0 to the field Access List Entry. Click Confirm to save the 0.0.0.0/0 whitelist.
Afterwards, navigate to the Clusters page by clicking Deployment > Database via the left navigation panel.
Then, click on the Connect button under the name of your cluster (the default name was Cluster0, if you did not change it). A screen should then appear.
Under Connect Your Application, choose the connection security Drivers.
In the new screen:
Select Node.js as the Driver and Version 5.5 or later in Step 1.
Ignore Step 2.
Copy the URL Connection String in Step 3. Then:
Replace <password> in this connection string with the password you used when creating the MongoDB user in Step 4 earlier (hint: replace ALL of <password>, including the < and > with the value of your password).
Between the backslash ('/') and question mark ('?'), insert the name of your cluster (the default name was Cluster0, if you did not change it).
Keep this URL Connection String handy (record it somewhere, but do not share it online) as you will use it later in your application code to connect Truman to this database.
(optional) Download MongoDB Compass
MongoDB Compass is the GUI for MongoDB. It is a free interactive tool that lets you easily see the objects/data in the database. It is also helpful for querying, optimizing, and analyzing MongoDB data.
This is an optional step only if you want to easily see the objects in the database, which is helpful for testing purposes (you can skip this step if you would like).
Downloading the code from GitHub
The most recent codebase for The Truman Platform can be found here: https://github.com/cornellsocialmedialab/truman_2023.
This repository contains the most recent code (last updated in September 2023), which includes a variety of updates since the original project (which was created in 2019). We recommend using this repository.
However, if you would like to use the original project repository, you can find it here: https://github.com/cornellsml/truman.
Step 1: Create your own Truman repository (codebase) using the most recent codebase
You will use the Truman codebase as a template to create your own code repository of Truman. This allows you to create your own projects without affecting the main Truman source code.
Go to GitHub, and sign into your account.
Then, go to https://github.com/cornellsocialmedialab/truman_2023.
Click the green button that says Use This Template. Then, click Create a new repository.
You should be redirected to a new page with a form to create a new repository. Complete this form:
Give your repository a name (for example: "truman-socialnormsproject").
Set a description for your repository (optional).
Select the "Public" option to make your repository public.
Click Create repository.
You now have your own version of Truman on your own GitHub account!
Step 2: Cloning your Truman project onto your local computer
Now that you have a version of Truman on your own GitHub account, clone this codebase onto your local machine. Cloning creates a local copy of the code on your own laptop.
Having a local copy of the code on your laptop allows you to make changes to the code and test and observe them locally before pushing them publicly to the repository or for deployment.
For instructions on how to clone your repository, see here.
You can either use (1) the terminal/command prompt (as seen in the above instructions) or (2) the GitHub Desktop application, which you downloaded earlier (see here for instructions on how). If you are unfamiliar with using the terminal/command prompt, we recommend using the GitHub Desktop application.
Be sure to remember which file directory you cloned the repository to on your local computer.
Setting up Truman
Now that you have a local copy of the Truman codebase on your own laptop, we will complete some steps and configuration to get it running.
Step 1: Install the project package dependencies
Open the terminal/command prompt.
cd
(change directory) into the file directory you cloned the repository to by entering the commandcd <file-directory-path>
and replacing <file-directory-path> with the file directory path. For example, if you cloned the repository into C:\Users\JohnDoe\Documents\GitHub\truman you would entercd C:\Users\JohnDoe\Documents\GitHub\truman
in the terminal/command prompt.Next, enter
npm install
in the terminal/command prompt. This installs all the external node libraries for Truman . You are going to see a bunch of lines of code come and go on the screen. This is completely normal. This may take a few minutes as the project needs to download and install a lot of libraries. Afterwards, you should see a screen similar to the one below, with a message like “added XXXX packages….”, indicating the installation was successful. Note: If the installation prompts you to update npm, you can update npm. However, it is not necessary.
Step 2: Create and edit the environment file (.env)
The purpose of the .env (environment) file is to locally store environment-specific variables (with the format KEY=VALUE) on the machine rather than on the cloud server. This is important for sensitive information such as the MongoDB connection string, since we don't want to be visible to the public or else others could have access to the database.
An example .env file is provided in the codebase (.env.example) to help you create this .env file. You will now create the .env file and add the MongoDB URL connection string that you saved earlier. This will connect your project with the database you created earlier.
Copy the .env.example file:
Enter the following command in the terminal (in the file directory of your project):
cp .env.example .env
This creates a copy of the file .env.example to .env.You should now have a .env file, with all the environment variables in the .env.example copied over.
NOTE: DO NOT copy the .env.example file by copying, pasting, and renaming the file in the File Directory/Explorer. You will encounter errors if you do this.
Update the environment variables (specifically the MongoDB URL connection string) in your newly created .env file:
Edit the .env file with nano by entering
nano .env
in the terminal.Replace the value of the key MONGODB_URI= with the URL that you recorded down earlier to tell the application which database to connect to (i.e. replace the value to the right of the equals signs with the connection string; see the screenshot below as an example). Make sure that there are no spaces between the key and the connection string.
Exit the nano window with CTRL+X.
Before exiting, you will be asked if you want to save your changes to the file. Press Y and hit Enter to save.
Next, you will be asked to give the file a name. You do not need to give the file a new name, so simply hit Enter again.
Step 3: Populate your database
Now that you have indicated in your project which database to connect to, it is time to populate the database with the simulation content.
Enter
node populate.js
in the terminal/command prompt. This command runs the script populate.js, which connects to the MongoDB database you just defined in the .env file and uploads the simulation data found in the csv files in the ./input folder in the project directory to the MongoDB database you created.You should see something printed similar to this.
After the script is done running, go to https://cloud.mongodb.com/ to look at the database you just populated.
Click Database > Clusters via the left navigation panel.
Click on the name of your cluster (the default name was Cluster0, if you did not change it).
Under Collections, you should now see 3 new collections in your database, called “actors”, “scripts”, “notifications”. These are the objects that form the simulation (actors, posts, comments, notifications etc.)
Note: If you downloaded MongoDB Compass earlier (an optional step), you can also view your database via MongoDB Compass. This may be an easier interface to use than the web browser interface if you plan to manipulate and check the objects in your database often: Open MongoDB Compass on your local machine. When it prompts you to enter a connection string, enter your MongoDB Connection String and click Connect. You should then see a very similar interface as the picture above.
Using Truman for the first time!
Now that everything is installed, we can now run Truman on your local device! Enter
npm run dev
in the terminal/command prompt. This starts your server.Then, go to http://localhost:3000/ in the browser of your choice.
You should be able to see a screen like the one below.
Congratulations! You now have your own version of Truman running on your local computer! Create a new account and try out Truman for yourself.
Last updated