How to install node 13+ (Guide)

good idea! didn’t know that!

well seems to be working! appended it to the bash_profile and it has stayed as 13.11.0!

in the console…

Yeah, the install script doesn’t end up sourcing the file. You could do a preinstall hook for pnpm that sources the .bash_profile file.

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?

this method applies to ubuntu 16.03 LTS, which is the image all containers run on. Meaning it would work in glitch.

actually, this installs into the project directory in a hidden folder. Which is handy

2 Likes

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.

That seems like something we would need explaining by someone from @glitch_support

1 Like

Thank you @random!

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

# https://support.glitch.com/t/how-to-install-node-13-guide/20430
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.0/install.sh | bash
export NVM_DIR="/app/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
nvm --version
nvm install node
nvm use node

Then I modified by package.json

{
...
...
  "scripts": {
    "start": "bash install_node_13.sh && node server.js"
  },
...
...
}

The resulting logs

logs

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
3 Likes

@mfekadu

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.

1 Like

Great job @mfekadu !

1 Like

@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.

That makes sense!

Honestly, I was just in the mood to throw code together and get quick prototype.

Good thinking about code efficiency @MGPlayzYT !

2 Likes

(Sorry, I don’t mean to reply to a topic that is a few months old)
I’m going to move this to #tutorials, is that ok?

2 Likes

yeah that’s fine! @aboutdavid

1 Like

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.

1 Like

Please kindly make a new thread and we’ll help ya there :slight_smile:

1 Like

.env and .bash_profile are same - put echo hi in .env and it executes it when you open the terminal.

2 Likes

Yes, but i don’t think people want to do that

Sorry to bump this but you can now change this in your package.json under engines -> node. Something like 13.X

5 Likes