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?
Asked
Active
Viewed 261 times
1

Brian David Berman
- 7,514
- 26
- 77
- 144
-
e.g.: you have a file called knockoutValidation.js located in your root folder of nodejs. Then you could wrap your validation and export that wrapper (object) by module.exports = myValidationObject. The node server can require this wrapper by require('knockoutValidation'); Is that what you was after? Furthermore I can recommend the node module "is my json valid" it's pretty nice and on json.schema.org you can generate your valid object formats – marcel Jul 01 '15 at 08:36
-
No. I'm just looking to reference my javascript files that exist in my .NET application and not have to copy them into my root folder in nodejs. – Brian David Berman Jul 01 '15 at 14:38
-
1If nodejs and the .NET application have access to this file (they are located on the same system running by the same user) you could add a service to your .NET Application that returns the absolute path to the js file. Then use this path at the initializing process of nodejs to referr to that file. You can use absolute paths with nodejs as well. It doesn't have to be in your app-folder... that was just an example. – marcel Jul 02 '15 at 08:55
1 Answers
2
This technique appears to work.
var LegacyCode = require('../../../OtherProject/SomeFolder/legacy.js');
// ...
LegacyCode.helloworld();

Michael Blankenship
- 1,639
- 10
- 16