Getting started


  1. Operating system requirement
    Njs2 Framework is designed to operate in Linux based operating systems.
  2. Install node.js and essential build tools
    Download and Install Node.js v12 (v12.22.1)
  3. Install Njs2 CLI tool
    Start by installing the CLI tool globally using npm.
    npm install -g @njs2/cli
  4. Creating Project
    This command can be used to create a new Njs2 project in the current directory and also generates the project structure.
    njs2 project <project-name>
  5. Creating Endpoint
    This command creates a new REST Endpoint in the current Njs2 Project.
    njs2 endpoint helloWorld
    Following are the files created under methods directory.

    src/methods/helloWorld/init.js
    class ExampleHelloWorldInitalize extends baseInitialize {
    
      constructor() {
        super();
        this.initializer = {};
        this.initializer.isSecured = false; // values: true/false
        this.initializer.requestMethod = ['GET']; // requestMethod: ['GET', 'POST', 'PUT', 'DELETE']
      }
    
      getParameter() {
        const param = {};
    
        return { ...param };
      }
    }
    
    module.exports = ExampleHelloWorldInitalize;
    src/methods/helloWorld/action.js
    class ExampleHelloWorldAction extends baseAction {
      async executeMethod() {
        this.setResponse("SUCCESS");
        return "Hello World!..";
      }
    }
    module.exports = ExampleHelloWorldAction;
    
  6. Run the project
    This command runs a local dev server at PORT: 3000 from the current directory with the runtime specified as options to this command.
    njs2 run
  7. Then open the browser and visit the following url:http://localhost:3000/example/helloWorld
  8. Ctrl+cto stop the server