how to use the webodf editor in localhost with node.js

眉间皱痕 提交于 2019-12-01 11:53:43

I am not not sure what you currently have . But This is how you can configure an application using node.js to serve html files and view/edit odf files.

Lets Start with your Node.js Server

  1. First Create an index.js file(name it whatever you want)in our application directory,then initialize node application using node init.

    We will have following folder structure : -

    • ./ document-editor
    • ../app (our html code and libraries)
    • ../index.js
    • ../package.json
    • ../And some other auto-generated files.
  2. Include all the modules necessary.We are going to use Express,Multer and other util libraries.

    var express = require("express"); 
    var multer = require('multer');  //for file handling
    var util = require('util');
    var app = express();   // init express app
    
  3. Configure Routes and Html files to be served on user request to you server.

     app.use(express.static('app')); // use this as resource  directory
    
     //APP ROUTING URL => FUNCTIONS
     app.get('/', function (req, res) {
      res.sendFile(__dirname + "/app/index.html");
     });
     // this means when we get a request on 'myAppContext/' url provide   
       index.html
    
  4. Start the Server

     //START THE SERVER 
       app.listen(3000, function () {
         console.log("Listening on port 3000");
      });
    

Note* : Make sure you have node.js envoirnment installed on your system before you start.

Now Lets Look at how we include webodf to our application.

  1. First create a directory in your main folder(we name it 'app'), where all the html,styles and scripts..etc will be stored.

    • /app (our html code and libraries)
    • ../index.html
    • ../script
      • ..wodotexteditor-0.5.9(folder)
      • ..myScript.js
    • ../styles
    • ../images
    • ../And some other files.
  2. Create an index.html file and include webodf and/or Editor JavaScript libraries(Contains Webodf included in build... so need to download separately).

  3. Create a container element and local script necessary to run webodf editor.Make sure to add a odt file to directory for you test or you can use the one which comes with wodo-editor.

    You can refer this link for creating a local webodf editor using wodo-text-editor and complete the above to steps(2 & 3).

  4. After we have done the above things,we will go into our root directory and run 'node index' command.... and that's it folks.

    Just hit localhost:3000/ and you will see a workable webodf editor.

I hope this helps to get started with node.js and webodf. I will soon create and full application with open/edit and save features using webodf and node.js. Thanks :)

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!