asp.netjsonnode.jsclient-side-validationserver-side-validation

Reference existing javascript files for server side node.js validation


I have a situation in which I'd like to reuse some existing JavaScript (Knockout.JS) validation that I use on the client side to re-validate some models (JSON) on the server side. I'd like to introduce a Node.JS web application to handle this, which I'd be calling from ASP.NET. I'm finding that Node.JS applications rely on a certain degree of convention, in terms of where files/folders are located and I wanted to ensure that I can literally reach out to where my existing JavaScript files are and not have to make copies, etc. Is this possible?


Solution

  • This technique appears to work.

    var LegacyCode = require('../../../OtherProject/SomeFolder/legacy.js');
    // ...
    LegacyCode.helloworld();