How to create APIs in node and Executable file for Node.js project


Prerequisite: Node should already installed  in the system
  1. Create a project directory and From inside the directory open CMD and type "npm init” This will ask some basic details to  create package.json.
  2. Install dependencies like express JS etc as per project requirements.
  3. After creating package.json create a main file ex- app.js
Create your  app.js file as.

var express = require("express");
var bodyParser = require('body-parser');
// Set up the express app
const app = express();
app.use(bodyParser.json());
app.get("/", function(req, res) {
          return res.send({"Response":"your project is ready"});
    });
const PORT = 5000;
app.listen(PORT, () => {
  console.log('server running on port',PORT)
});

Your project is now ready. Execute it via using below command:
node app.js
You can Test the request using URL- http://localhost:5000/

Now it's time to create .exe

  1. Install node package pkg. Using command “npm install pkg -g” .exe
  2. After installing run “$ pkg app.js --output EDS.exe” from project directory.
  3. Your .exe will be available on the same directory.
  4. Can be used as windows startup service. (create shortcut and place shortcut to shell:startup directory.)

NOW execute it and enjoy your routes…
How to create APIs in node and Executable file for Node.js project How to create APIs in node and Executable file for Node.js project Reviewed by Ishan Dev Shukl on May 13, 2019 Rating: 5

No comments:

Thanks a lot for your valuable Comment!

Powered by Blogger.