An Express GraphQL server app using GraphQL Yoga and Prisma that serves as the server to Next Store.
- GraphQL: Query language for APIs
- GraphQL Yoga: Express GraphQL server
- Prisma: GraphQL database interface
- Bcryptjs: Password hashing
- JSON Web Token: User authentication
- MailTrap: Development emailing
- Postmark: Production emailing
- nodemailer: Sending email with NodeJS
- Stripe: E-commerce API
# ./server/
$ npm install
Create an .env file which will be updated during setup. See also .env_example.
# ./server/.env
NODE_ENV=development
APP_SECRET=my-super-secret
HOST=http://localhost
PORT=4242
DEV_CLIENT_URL=http://localhost:7272
PROD_CLIENT_URL=
PROD_SERVER_URL=
CLOUDINARY_API_KEY=
CLOUDINARY_PRESET=nextstore
CLOUDINARY_SECRET=
PRISMA_DEV_ENDPOINT=
PRISMA_PROD_ENDPOINT=
PRISMA_SECRET=
PRISMA_MANAGEMENT_API_SECRET=
STRIPE_SECRET=
MAILTRAP_HOST=
MAILTRAP_PORT=
MAILTRAP_USER=
MAILTRAP_PASS=
POSTMARK_HOST=
POSTMARK_PORT=
POSTMARK_USER=
POSTMARK_PASS=
- Create and access your Cloudinary account.
- Grab your API key (CLOUDINARY_API_KEY) and API secret (CLOUDINARY_SECRET) from the main console page.
- Create a folder where uploads will be stored.
- Add an upload preset to set the dimensions uploaded files will be transformed into. (CLOUDINARY_PRESET)
- Create or access your MailTrap account.
- Create a demo inbox and check the SMTP Settings page for the Host, Port, Username, and Password credentials to be used in your env file.(MAILTRAP_HOST, MAILTRAP_PORT, MAILTRAP_USER, MAILTRAP_PASS)
(Postmark setup is unnecessary for local)
- Create or access your Stripe account. (Confirm your account in your email if creating an account)
- Click the API keys link under the Developers tab.
- Grab the Publishable Key and update STRIPE_API_KEY on the client side with this key (aka ./client/config.js)
- Grab the Secret key and update STRIPE_SECRET in the .env file on the server side (aka ./server/.env)
- Create or access your Prisma account.
- Globally install prisma then login to prisma in the terminal.
# ./server/
$ npm install -g prisma
$ prisma login
- Set up Prisma by using the prisma-cli in the terminal to generate your endpoint.
# ./server/
$ prisma init
# ? Set up a new Prisma server or deploy to an existing server?
> Demo server
# ? Choose the region of your demo server
# (for me it was 'answart/demo-us1')
> PRISMA-WORKSPACE/PRISMA-SERVER
# ? Choose a name for your service
> next-store-dev
# ? Choose a name for your stage (dev)
> dev
# ? Select the programming language for the generated Prisma client
> Don\'t generate
It will generate the files datamodel.graphql and prisma.yml.
-
Place the endpoint url from the generated prisma.yml as the PRISMA_DEV_ENDPOINT in your .env file. Delete the generated files as the endpoint is now in the .env file and generated files are already configured in the prisma directory.
-
Run the deploy script. Any changes from this point on can be deployed with the following script:
$ npm run deploy:dev
# ./server/
$ npm run start:dev
View server at localhost:4242.
Command | Description |
---|---|
npm install | Install dependencies |
npm run deploy:dev | Deploy changes to Prisma server |
npm run start:dev | Launch server app at localhost:4242 |