javascript - Sharing code between AngularJS and Nodejs -


What is the best way to share code between frontend and backend using

javascript Especially nodes: and angular world ?

The thing is that we are using the same enums and constant values ​​ in both the backend and the frontend error code Now as we copy and paste each change in both platforms, which is not a good solution, there are some services that can be shared.

I have seen libraries like browserify ; But that is not what I see. I am looking for a solution similar to Maven dependence in the same way as java . In java , libraries can be shared easily by using maven , while I do not find any way to do this in such a javascript Could. Is there a way to separate these services and use them as nodejs for npm and angularjs for bower Give it as at liberty? Or what are the ways to share the same code between the frontend and the backend?

There are several ways to do this. First of all, you can create a new package, which is required for the front end code through the Kunj and through the NPM for the backend code. I've got several packages published for both systems.

- Information about installing modules which are not in the registry

- All methods of installing with npm (Private Gitb Auth: git + Ssh: //git@github.com/ [org] / [repo] )

Simply create a new module with your shared data and install it using both the package manager Both allow you to install unpublished modules, so if it is private data then you can keep it in this way Are.

If your front end is required, then need.js make it available in your node backend, or if you are only using a legacy window code, Can:

  var mydata = {}; If (type window! == 'undefined') {window.mydata = mydata; } Other {module.exports = mydata; }  

If you are sharing a lot of data, then I would recommend using a browser to write your entire codebase in general and to generate your customer bundle by looking at my browser. I advise to give

, including information about using browser information

Comments

Popular posts from this blog

Member with no value in F# -

java - Joda Time Interval Not returning what I expect -

c# - Showing a SelectedItem's Property -