Transfer a MERN application to Linode's MERN Marketplace App
Traducciones al EspañolEstamos traduciendo nuestros guías y tutoriales al Español. Es posible que usted esté viendo una traducción generada automáticamente. Estamos trabajando con traductores profesionales para verificar las traducciones de nuestro sitio web. Este proyecto es un trabajo en curso.
The Linode Marketplace App for the MERN stack (MongoDB, Express, React, Node.js) is a great way to create the base configuration equipped with all the essentials for a MERN stack quickly, however the Marketplace APP itself will still require tuning to host your MERN application. Transferring an application to a new host for example, can be a complex process depending on the specifics of your configuration. This guide was designed to serve as reference for users currently undergoing the migration process, and aims to clear up potential confusion and common issues that can occur.
Before proceeding with any migration, it is first recommended that the Marketplace APP for the MERN stack is fully deployed. This will install an up to date version of most of the essentials required for many working MERN applications including the following:
Additionally, this will install the default
hello-world react application which you may opt to remove to.
hello-world Flask application included as part of the MERN Marketplace App can be removed manually from the command line. For some use cases and application,this step may be required to ensure that the necessary resources are available. The commands to remove this application are as follows:
sudo systemctl disable hello-world sudo systemctl stop hello-world sudo systemctl daemon-reload npm uninstall -g create-react-app sudo pkill -f node sudo rm /lib/systemd/system/hello-world.service
Before, proceeding with any remote transfer, it is strongly recommended the original host that will be transferring data to the Linode has Backups available to restore from. While standard backup solutions will work for the majority of the MERN Stack, a database dump for MongoDB should be performed by using the mongodump command.
A MongoDB database dump can therefore be performed from the home directory with the following command:
cd && mongodump
Once completed, the database dump will be saved in the
/dump/ suc-directory by default from the working directory. The
.bak file contained within this directory can then be used to restore your database to the new Linode. The full dump directory should next be transferred over to the MERN stack Linode. To do this, first SSH into the MERN stack Linode and enter the following command, using syntax similar to the following including the
-r flag, which will recursively copy all files from the targeted directory on the remote system to the local path designated on the linode:
scp -r your_linode_username@your_linode_ip:/path/to/dump/directory /path/to/your/local/directory
scp command can be used from the command line on the MERN stack Linode to copy the node project. Syntax for this command is as follows, and uses the
-r flag to recursively copy all files within the targeted directory of the Node project being transferred:
scp -r your_linode_username@your_linode_ip:/path/to/your/directory /path/to/your/local/directory
Once the file transfer is completed, Rebuilding the MERN application is generally a simple process, completed through the following steps:
Change your working directory to the directory which contains your node project:
Install the node project using NPM or a package manager of your choice to install all node modules:
npm installThe packages installed using the
npm installcommand will install all node modules included in the project directory. This does not include all modules in any subdirectory. If your project is reliant on additional underlying modules, you will need to navigate to the directory where their configuration information.
Restore the MongoDB database by navigating to the install location of the
dumpfolder containing your database dump. If this was installed in the
/homedirectory, then the following commands will navigate to this directory, and then perform the database restore:
cd sudo mongorestore
Start the database if it has been shut down for any reason:
sudo service mongod start
Navigate back to the project directory, and direct node to run any .js files to activate and begin serving your content. Syntax for this command is usually as follows:
cd mynodeproject sudo node server.js
Once these steps are completed, your node configuration should successfully be running.
You may wish to consult the following resources for additional information on this topic. While these are provided in the hope that they will be useful, please note that we cannot vouch for the accuracy or timeliness of externally hosted materials.
This page was originally published on