This starter app includes all the files necessary to get started with a basic, hello world app. This app uses NextJS, BigDesign, Typescript, and React.
To get the app running locally, follow these instructions:
- Use Node 18+ and NPM 8+. To check the running versions, use the following commands:
node -v
npm -v- Clone and/or fork the repo and install npm packages:
git clone git@github.com:bigcommerce/sample-app-nodejs.git my-bigcommerce-app
cd my-bigcommerce-app
npm install- To expose your app server using an HTTP tunnel, install ngrok globally, then start the ngrok service.
Starting a local HTTP tunnel with ngrok requires you to create an ngrok account and add your ngrok authtoken to the ngrok config file.
ngrok config add-authtoken $YOUR_AUTHTOKENYou can use npm to install ngrok:
npm install -g ngrokAlternatively, MacOS users can use the homebrew package manager:
brew install ngrokStart ngrok on port 3000 to expose the default Next.js server:
ngrok http 3000- Use the BigCommerce Developer Portal to register a draft app. For steps 5-7, enter callbacks as
'https://{ngrok_url}/api/{auth || load || uninstall}'. Get thengrok_urlfrom the ngrok terminal session.
https://12345.ngrok-free.app/api/auth # auth callback
https://12345.ngrok-free.app/api/load # load callback
https://12345.ngrok-free.app/api/uninstall # uninstall callback- Copy
.env-sampleto.env.
cp .env-sample .envIn the
.envfile, replace theCLIENT_IDandCLIENT_SECRETvariables with the API account credentials in the app profile. To locate the credentials, find the app's profile in the Developer Portal, then click View Client ID.In the
.envfile, update theAUTH_CALLBACKvariable with the auth callback URL from step 4.In the
.envfile, enter a secretJWT_KEY. To support HS256 encryption, the JWT key must be at least 32 random characters (256 bits).Configure the data store. This project was written to use Firebase or MySQL
In the
.envfile, specify theDB_TYPE.If using Firebase, copy the contents of your Service Account JSON key file into the
sample-firebase-keys.jsonfile. This file can be generated by:- Creating a new project in Firebase
- Adding a Cloud Firestore
- And generating a new Private Key under Project Settings > Service Accounts See the Firebase quickstart (Google) for more detailed information.
If using MySQL, supply the
MYSQL_config keys listed in the.envfile, then do the initial database migration by running the following npm script:npm run db:setupStart your dev environment in a dedicated terminal session, separate from
ngrok.
npm run devIf you relaunch
ngrok, update the callbacks in steps 4 and 7 with the newngrok_url. You can learn more about persisting ngrok tunnels longer (ngrok).
- Consult our developer documentation to install and launch the app.
In production, you must build and run optimized version of the code. Use the following commands to get started:
When you run the
startscript, specify a port number using the-pflag. Otherwise, the process will fail.
npm run build
npm run start -p 3000