To build and run this app locally you will need a few things:
- Create a new DB called
Gateways
- Run Mongo db on
mongodb://localhost:27017/Gateways
, as provided onBack/config/default.json
- Install dependencies
cd <project_name>/Back
npm install
- Build and run the backend project with auto reload (nodemon)
npm run server
- Build and run the project
npm run start
Finally, navigate to http://localhost:5050/
and you should see the API running!
All the different build steps are orchestrated via npm scripts.
Npm scripts basically allow us to call (and chain) terminal commands via npm.
This is nice because most JavaScript tools have easy to use command line utilities allowing us to not need grunt or gulp to manage our builds.
If you open package.json
, you will see a scripts
section with all the different scripts you can call.
To call a script, simply run npm run <script-name>
from the command line.
You'll notice that npm scripts can call each other which makes it easy to compose complex builds out of simple individual build scripts.
Below is a list of all the scripts this template has available:
Npm Script | Description |
---|---|
tsc |
Transpiles TypeScript codes to JavaScript. |
watch-tsc |
Transpiles TypeScript codes to JavaScript, with auto reload. |
deploy |
Runs node on dist/server.js which is the app's entry point. |
watch-deploy |
Runs node on dist/server.js which is the app's entry point, with auto reload. |
server |
Transpiles TypeScript codes to JavaScript then run node on dist/server.js with auto reload. |
start |
Transpiles TypeScript codes to JavaScript then run node on dist/server.js . |
Since we're developing with TypeScript, it is important for the codes to be transpiled first to JavaScript before running the node server. It is best to deploy the app using: npm run server
or npm run start
command.
Attached postman collection to test the APIs without using the UI. Includes 5 APIs
GET: http://localhost:5050/api/gateways
GET: http://localhost:5050/api/gateways/{gateway_id}
GET: http://localhost:5050/api/devices/{gateway_id}
POST: http://localhost:5050/api/gateways
POST: http://localhost:5050/api/devices
DELETE: http://localhost:5050/api/devices/{gateway_id}
cd <project_name>/Front
npm install
This project was generated with create-react-app CLI
Run npm start
for a dev server. Navigate to http://localhost:3000/
. The app will automatically reload if you change any of the source files.
Run npm run build
to build the project. The build artifacts will be stored in the build/
directory.
Just run the file automated-build.sh
and ti will install all npm packages and make the dist
folder for and backend and build
folder for frontend.