Basic recipe book for cooking great things.
The recipe book app uses mongodb to store the recipes. You'll want to set up or point to a mongo database.
On macOS with homebrew
Install mongodb
brew tap mongodb/brew
brew install [email protected]Start mongodb with
brew services start [email protected]Stop mongodb with
brew services stop [email protected]This project uses migrate-mongo to set up the recipe collection in mongoDB and to migrate changes to the schema and data. To get going, install migrate-mongo.
npm install -g migrate-mongoThen from the dbmigrations directory, run
migrate-mongo upThis will create the recipes collection and its validation schema. Now you can add recipes using the UI, or use the sample queries provided in docs/mongo-schema.md after the example schema definition.
Using mongosh or some other tool, create the recipeBook database with the use recipeBook command. Then create the recipes collection with the schema validator.
See mongo-schema.md for the schema and a few example recipes insert commands.
This project uses migrate-mongo to manage the mongo database and apply and rollback changes. Also see All you need to know about MongoDB schema migrations in node.js for a nice write-up for using migrate-mongo.
In the dbmigrations directory,
migrate-mongo create <create some_description_of_changes>This will create a migration file in the dbmigrations/migrations directory, to which you can add the migration. Then to apply the migration
migrate-mongo upAnd to revert to the prvious version
migrate-mongo downFor raspberry π 4b use the 64-bit debian images from raspberry pi
Use the set up docs as a base.
The Raspberry Pi Imager can be used to image the downloaded image onto the SD card. Just select the "Use Custom" option from the main menu when selecting the operating system.
binaries and instructions for 4.4.8
Now the above link also has binaries for mongo 5.0.5 (thanks Andy Felong!)
Once installed, you can start the mongo database with:
sudo systemctl start mongodbTo see the status of the service:
sudo systemctl status mongodbTo stop the service:
sudo systemctl stop mongodbTo enable the service to start automatically at boot:
sudo systemctl enable mongodbnpm install pm2@latest -gTo start with pm2, in the nextjs project directory, after running
npm run buildin the same directory, run
pm2 start npm --name "recipes" -- start -- -p 8080Once started, you can get the status, stop, start, remove the process from any directory:
$ pm2 delete 4
[PM2] Applying action deleteProcessId on app [4](ids: [ '4' ])
[PM2] [nextapp](4) ✓
┌─────┬────────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id │ name │ namespace │ version │ mode │ pid │ uptime │ ↺ │ status │ cpu │ mem │ user │ watching │
├─────┼────────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 6 │ recipes │ default │ N/A │ fork │ 16125 │ 4m │ 0 │ online │ 0% │ 53.9mb │ pi │ disabled │
└─────┴────────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘pm2 stop <id>
pm2 start <id>
pm2 delete <id>For more details about the process:
pm2 show recipesTo have pm2 maintain the list of processes and start-up when the server restarts see the pm2 persistent application docs.
A good starting point is nginx beginners guide and nginx reverse proxy.
On debian (works on raspian) use apt and the default debian repository
sudo apt update
sudo apt install nginxTo verify that nginx has been installed properly, show it's version
sudo nginx -versionThen edit the /etc/nginx/nginx.conf file.
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 768;
# multi_accept on;
}
http {
server {
# all incoming request on port 80 (listen 80 is the default value and is omitted here)
# get mapped to localhost:8080 on which the recipes are running
location / {
proxy_pass http://localhost:8080/;
}
}
}
Now start nginx
sudo nginxSome useful commands:
sudo nginx -s reload,sudo nginx -s stop.
This should already have set up nginx as a service. You can verify this with
systemctl status nginxAnd you should be good to go.