MERN Stack Authentication using Sequelize (MySQL as dialect) for backend template.
create .env
file in root project or in server (recommended in root because hosting provider sometimes need to put in root directory), and create these variables:
DB_HOST = localhost
DB_PORT = 3306
DB_USERNAME = root
# leave empty if dont need password
DB_PASSWORD =
DB_DATABASE_NAME = my_database
ACCESS_TOKEN_SECRET = random-string
REFRESH_TOKEN_SECRET = different-random-string
the value could be vary depending on your local database setup and also the dialect could be vary.
dont forget to create my_database
in your database first or change it to other name that exist.
only need to run this for installing both client and server.
npm run install
this command will run both client and server development server. run it in root directory (not client or server).
npm run dev
customize the install command to follow the installation part, if start
command failed, customize it to look like this npm start --prefix server
,
this is sometimes happen when npm cannot be used inside package.json a.k.a internal npm command through npm command. make sure you set NODE_ENV
variable to "production".
if you deploy in a subroute of your hosting url, for example https://mysite.com/myproject
:
in {root}/.env
add
BASE_PATH = /myproject
VITE_BASENAME = /myproject
you could modify /myproject
to follow your subroute of your hosting provider.