Local development
Codehooks supports local development to test before deployment. The CLI has a built in local server which lets you run your application locally to test and debug before deploying to the Codehooks cloud.
First you need to install the CLI.
npm install codehooks -g
Getting started with a local project
You don't need to create a project to start with, just create a directory with an index.js file and a package.json file to get started.
mkdir mytest
cd mytest
touch index.js
npm init --yes
npm install codehooks-js
Then open the index.js in you favorite code editor and enter the following JavaScript code.
import app from 'codehooks-js' // Standard JS lib for express style code
// Create a GET endpoint route
app.get('/hello', async (req, res) => {
console.log("I run locally, cool!");
res.json({"message": "Hello local world!"});
});
export default app.init(); // Bind functions to the serverless runtime
Start the local development server with the CLI command in your project directory. Default port is 3000.
coho localserver --port 3000
Codehooks listening on http://localhost:3000
tip
Auto reload changes with nodemon
Using nodemon to automatically reload code changes (install: npm i nodemon -g
)
nodemon -w . -x 'coho localserver --port 3000'
[nodemon] 2.0.18
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `coho localserver --port 3000`
Codehooks listening on http://localhost:3000
Read more about the CLI command here