Is this method supported by Glitch? I would assume that nothing outside the project directory should be expected to persist changes in the event of infrastructure upgrades?
Are you asking if the changes would be accessible outside the application directory? If so, the answer would be yes. Sourcing (or, rather, executing) the nvm script would append some portion of the nvm-aliased Node.js binaries to the user’s PATH variable which would be accessible throughout the entire system. The issue is that nvm initialization, depending on how the user chooses to set it up, might only occur when the user opens a shell (in which case, would not occur without the user having opened a terminal in the Glitch editor).
Manually installing nvm and installing Node.js through it would be one way to ensure the latest version Is available in the container.
Is there a way to make the version stay on v13? Because everytime I change something in the “package.json” file or install a package through the console, it just reverts back to v12.
I converted what you shared into a script that runs on npm start it seems to install node 13 properly. The only downside is a much slower startup time.
First I made a file install_node_13.sh with @random’s code
node v12.0.0, with pnpm
3:10 PM
Installing...
3:10 PM
Performing headless installation
3:11 PM
3:11 PM
Total install time: 29569ms
% Total % Received % Xferd Average Speed Time Time Time Current
3:11 PM
Dload Upload Total Spent Left Speed
3:11 PM
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:05 --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:05 --:--:-- 0
100 11329 100 11329 0 0 1793 0 0:00:06 0:00:06 --:--:-- 1810
3:11 PM
=> Downloading nvm from git to '/app/.nvm'
3:11 PM
Cloning into '/app/.nvm'...
3:11 PM
=> * (HEAD detached at v0.33.0)
3:11 PM
master
3:11 PM
=> Compressing and cleaning up git repository
3:11 PM
3:13 PM
=> Profile not found. Tried (as defined in $PROFILE), ~/.bashrc, ~/.bash_profile, ~/.zshrc, and ~/.profile.
3:13 PM
=> Create one of them and run this script again
3:13 PM
=> Create it (touch ) and run this script again
3:13 PM
OR
3:13 PM
=> Append the following lines to the correct file yourself:
3:13 PM
3:13 PM
export NVM_DIR="/app/.nvm"
3:13 PM
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
3:13 PM
=> Close and reopen your terminal to start using nvm or run the following to use it now:
3:13 PM
3:13 PM
export NVM_DIR="/app/.nvm"
3:13 PM
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
3:13 PM
0.33.0
3:13 PM
Downloading and installing node v14.3.0...
3:13 PM
Downloading https://nodejs.org/dist/v14.3.0/node-v14.3.0-linux-x64.tar.xz...
3:13 PM
# 2.1%
## 3.4%
#### 6.4%
######## 11.9%
########## 14.3%
############## 19.7%
############### 21.9%
################## 25.5%
#################### 28.4%
###################### 31.3%
######################## 34.4%
########################## 37.2%
############################ 40.2%
############################### 43.8%
################################ 45.3%
################################### 49.5%
##################################### 52.7%
######################################## 55.8%
########################################## 58.6%
############################################ 61.7%
############################################## 64.2%
############################################### 66.2%
################################################# 69.0%
#################################################### 73.5%
####################################################### 76.5%
######################################################### 79.2%
########################################################### 82.6%
############################################################ 84.2%
############################################################## 86.3%
################################################################ 89.9%
#################################################################### 94.6%
###################################################################### 97.4%
######################################################################## 100.0%
3:13 PM
3:13 PM
Checksums matched!
3:13 PM
Now using node v14.3.0 (npm v6.14.5)
3:14 PM
Creating default alias: default -> node (-> v14.3.0)
3:14 PM
Now using node v14.3.0 (npm v6.14.5)
3:14 PM
💑🌄 Your app is listening on port 3000
You don’t always need to install it. Check to see if it’s there; if it is, don’t install it. You’ll have shorter start-up times.
I would go a step further and add it to a postinstall script so it can run after Glitch’s installation so you can keep the start script as just node server.js.
@mfekadu Thank you for the code. Also I don’t think curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.0/install.sh | bash
will be needed to run on startup because the nvm install script is already present. Tried the code without the curl script and it has faster startup time.
This is a really hacky way, but well - this still doesn’t enforce the editor to support the newest Node v14/15 features, I can’t make use of optional chaining / nullish coalescing at all.