Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mavagio/foody
Helps you with your dinner
https://github.com/mavagio/foody
Last synced: 28 days ago
JSON representation
Helps you with your dinner
- Host: GitHub
- URL: https://github.com/mavagio/foody
- Owner: mavagio
- License: mit
- Created: 2018-12-15T12:32:50.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-07T02:38:43.000Z (about 2 years ago)
- Last Synced: 2024-10-14T15:21:50.652Z (3 months ago)
- Language: TypeScript
- Homepage: https://foodytoday.herokuapp.com/start
- Size: 34.3 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 57
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
This project aims to help you with choosing recipes for dinner.
The following README provides detailed steps on how to run the code locally as well as how to deploy the application to Heroku.
In the last section explanation on how to create new endpoints is provided.
## How to run locallyPrerequisites
---------------
Make sure to have the following installed on your machine:
- mongoDB (make sure to have mongod running locally when running the code on a local machine)
- Node > 8.9 (!important)Run the code
---------------
- Install dependencies. From root directory run:
```
npm run install:dependencies
```
- Create .env file in server folder.
- Copy the following lines to .env file.
```
PORT=3000
DEV_DB='mongodb://localhost/boilerplateDb'
NODE_ENV='development'
JWT_SECRET='change_this_example_secret'
```
- (Optional) Add the following to .env file if you want to run MongoDB with cloud provider (e.g. Mlab):
```
PROD_DB={{the URI provided by mongoDB could providers, e.g. Mlab}}
```
- Run the application by starting the client and server separately:
```
cd server; npm start
```
```
cd client; npm start
```This will create the database locally. By running the server with the command:
```
npm run start:cloud
```
The server will run in production environment. In addition the server will try to connect to mongoDB form cloud provider.
## Technology stack
MEAN Stack with TypeScript
- MongoDB
- Angular 6+
- Express
- Node > 8.9
- TypeScript
- JavaScript## Creating a new endpoint
- Define your endpoint route in `server/src/api/routes/apiRoutes.ts`, example:
```TypeScript
app.route('/api/test/').get(apiController.test_get);
```
- Add function to handle the endpoint in `server/src/api/controllers/apiController.ts`, example:
```TypeScript
exports.test_get = (req: any, res: any) => {
testCtrl.getAll(req, res);
};
```## Creating a new model
- Add the new model to `server/src/api/models`, example:
```TypeScript
import mongoose = require('mongoose');
import {Schema, Document} from 'mongoose';export interface ITest {
name: string;
email: string;
type: number;
}const TestSchema: Schema = new Schema({
name: String,
email: String,
type: Number,
});export interface ITestModel extends ITest, Document {
}const TestModel = mongoose.model('Test', TestSchema);
export default TestModel;
```
- Add controller for your model to `server/src/api/controllers`,
the controller has to inherit from `baseController`, example:
```TypeScript
import Base from './baseController';export default class TestClass extends Base {
constructor(model: T) {
super(model);
}public insert = (req: any, res: any) => {
const obj = new this.model(req.body);
obj.save((err: any, item: any) => {
if (err) {
return console.error(err);
}
res.status(200).json(item);
});
}
}
```