0π
β
To create a REST-API with express.js, first initialize a node.js-project (npm init [-y]
). Then you install express.js
(npm install express
).
When you have your setup, you can create an index.js
-file, the server. In it, you will have to adapt the content of the express Hello World example, so that the route it accepts is not GET /
but POST /send-translation-suggest-email
. Then make sure your server listens to port 3000 (as you specified in the client-side code).
In the listener to POST /send-translation-suggest-email
, you can call the main
-method from your other file (make sure to import the file properly, with node.js
βs require
-syntax).
Then, you can call the backend server from the frontend as you wished.
Source:stackexchange.com