Skip to content

A template repository for creating Next projects with MongoDB

License

Notifications You must be signed in to change notification settings

jschaufele/nextjs-starter-1

 
 

Repository files navigation

nextjs-starter

Stack

  • React.js: Front-end
  • Next.js: API routes and server-side rendering
  • MongoDB: Permanently storing info
  • eslint: Automatically identifying and fixing code errors
  • prettier: Setting a common code style and fixing any issues

Setup

Updating Env Vars

  • For dev, update .env and next.config.js
  • For production, add the env vars to your host, NEVER commit .env to your VCS

MongoDB

A running instance of MongoDB is required this project.

  • Decide if you want to run MongoDB locally or remotely
  • Locally
    1. Download MongoDB Community Server
    2. Go through the installation instructions.
      • Leave the port at default 27017
  • Remotely
    1. Create a MongoDB instance on MongoDB Atlas
    2. In Security → Network Access: add the IP address 0.0.0.0/0 (all IPs)
    3. In Security → Database Access: Add new database user
    4. In Data Storage → Clusters: Find your cluster and click ConnectConnect your application and copy the connection string, set the username and password, and set this as MONGO_DB in .env
  • Create the nextjs database. (or choose another name, but make sure to change it in .env)
  • It's very helpful to install MongoDB Compass to see your database contents

Node

  1. Clone this project to your computer
  2. Navigate to this project in terminal and enter npm install
  3. Rename example.env to .env and fill it out with the dev config

Running

Development

To understand this code better, read the Code Tour.

  1. Run npm install
  2. Run npm run dev

Production

  1. Setup your host/vm and the necessary env vars
  2. Run npm install
  3. Run npm run start

Other Info

Styling

  • By default, this repository uses Next ^9.2.0 for styles, which includes native support for global CSS and CSS modules
  • However, this version only allows global css to be in pages/_app.js, which can cause issues with external packages
  • If you face this error, the solution is installing @zeit/next-css and adding it to next.config.js, however you cannot use css modules and global css together with this package (and it defaults to global).

About

A template repository for creating Next projects with MongoDB

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 87.3%
  • CSS 12.7%