# Nightscout in Railway
```{admonition} Too complicated? Not what you're looking for? :class: seealso Consider a hosted Nightscout service! Check for easier solutions [here](/index.md#nightscout-as-a-service). ```
```{warning} The free plan has been removed Jul 3rd for new users and Aug 1st for existing users. ```
```{card} ## Railway.app ![Railway](/vendors/img/Railway.png) ^^^ You can easily create a new Railway Nightscout site with a [MongoDB Atlas](/vendors/mongodb/atlas) database or a [Railway MongoDB database](/vendors/railway/database). **Pros**: * Nightscout fits in the 5$/month Hobby account * Easy to deploy or migrate an existing site from Heroku * Simple to use and troubleshoot * You can host several Nightscout sites within a single Hobby account * Can use a native Railway MongoDB database ($) **Cons**: * Your GitHub account must have been created more than 3 months ago * The railway.app domain is blocked for safety by some companies * Railway network model causes issues with some follower app and devices ```
## Set up a new Nightscout ### Create your Railway and GitHub accounts from a computer. ```{note} Do not change device/computer/browser during the setup process! If you have unexpected issues when creating your site, restart with another browser. ```
### Step 0: Create a database ```{note} Make sure you [created one](/nightscout/database) before starting your Nightscout web app creation with Railway. Come back here when you have a MONGODB_URI connection string. ``` ```{admonition} Migrating? :class: tip Copy the connection string from your previous platform: [edit the variables](/nightscout/setup_variables.md#nightscout-configuration) and look for `MONGODB_URI`. If you don't see `MONGODB_URI` but see `MONGO_CONNECTION` (**NOT** `MONGO_COLLECTION`): use its value. ```
### Step 1: Fork `cgm-remote-monitor` **Do you have a GitHub account?** ```{tab-set} :::{tab-item} I don't have a GitHub Account ::{admonition} Railway.app new security requirement :class: warning You cannot connect Railway to GitHub if you just created your account.
Your GitHub account needs to have been created months ago.



**Consider another platform.**
::: :::{tab-item} I already have a GitHub Account ### Update your Nightscout fork :::{include} /vendors/github/update_b.md ::: ```
### Step 2: Create a Railway account If you already have a Railway account, make sure you have a developper plan: go to **step g)**.
a) Open [Railway](https://railway.app) in a new browser tab and click `login`. Login with GitHub.
b) If the following screen shows-up, select `Authorize Railway App`.
c) Click on `Please agree to the new terms to keep on using Railway`.
d) Scroll down and click `I agree with Railway's Terms of Service`.
e) Scroll down and click `I will not deploy any of that`.
```{danger} The free plan will be removed Jul 3rd for new users and Aug 1st for existing users.
Documentation will be updated. ```
f) You should now see this. You've created your Railway account. If it still shows 200 hours, refresh your browser page.
g) You need to use Nightscout for more than one month: upgrade your account to a Hobby plan. Click on the `Starter Plan` information and select `Remove Resource Limits`.
Enter your credit card information and select `Subscribe to a Hobby Plan`. Your card will be billed 1$ that will be refund immediately. Bank fees won't be refund.
### Step 3 - Deploy Nightscout in Railway Select below how you want to do this: ```{tab-set} :::{tab-item} Using the Railway button :::{include} new_user_b.md ::: :::{tab-item} Using the help page :::{include} new_user_a.md ::: :::{tab-item} Migrate from Heroku :::{include} migrate.md ::: ```
Congratulations. You created your new Nightscout site with Railway. Click the site name to open Nightscout.
```{admonition} Recommended :class: hint You should [change your Railway site name](#change-your-nightscout-site-name) now in order to make it easier to remember. You can also do this later, **before setting your uploaders**. ```
```{include} /nightscout/first_setup.md ```

## Change your Nightscout site name Railways automatically makes a name when creating your new site. It is rather difficult to remember. You can change the site name but need to keep the `.up.railway.app` domain. 1. Select your Nightscout app 2. Go in `Settings` 3. In `Domains` go to the end of line and click the edit icon 4. Write your new name and check it's available Click `Update` Your Nightscout URL will now be `https://`*yoursitename*`.up.railway.app`
Change all your [uploaders](/uploader/setup/) and [follower](/nightscout/downloaders/) devices to reflect the new URL once verified correct functioning of your Nightscout site.
------ You have completed a new Nightscout site creation. The following section provides more information for database migration and variables edition that you might not need to use now. ------
## Editing Variables in Railway
### Method 1 - Web interface This is recommended when you only need to edit or add few variables. a) Open [Railway](https://railway.app) and click `login`. Login with GitHub.
b) Select your Nightscout project.
c) Select your web app.
d) Click on `Variables`.
e) You can perform various operations on your variables: 1. Add a new variable with `+ New Variable` 2. View the variable value with `Show Value` 3. Edit or delete the variable or its value with the line end menu
Note that each variable modification will redeploy your project.
### Method 2 - Raw Editor This is recommended when you must perform lots of changes to avoid multiple project redeploys. a) Open [Railway](https://railway.app) and click `login`. Login with GitHub.
b) Select your Nightscout project.
c) Select your web app.
d) Click on `Variables`.
e) Click on `RAW Editor` top right
f) You can access all your variables in a text editor, each line contains the variable name, the sign `=` then its corresponding value. `VARIABLE=value` Perform all your changes taking care of uppercase and lowercase information and click `Update Variables` when finished.
Once saved your project will redeploy. If deploy fails, check your modifications...