Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js multi package project?

I'm new to Node, coming from a Java background. These days I'm experimenting with each part of a full application: database, rest api, ui.

So far I wrote the database-backed logic, which runs on its own, processes text files, store data about them in the database and exposes a REST API to query that data. I'm now going to make the ui to navigate that data.

Would it be reasonable having a structure like this:

- (a) main project folder
    - (b) backend application (a Restify server responds to REST calls querying the database)
    - (c) ui application (an http server serves React static files)

If that makes sense, I would guess that:

  • (b) has a package.json with server- and rest- related dependencies (i.e. Restify, MongoDB, ...)
  • (c) has another package.json with dependencies for ui (i.e. React, Webpack, etc, but not Restify or MongoDB)
  • (a) has a third package.json which cares for installing each sub-project (I'd say by running npm install through hand-written npm-scripts). Otherwise, how do you usually handle such Node projects? Do you keep each application completely separate from the rest?

For those who know that tool, this mimics a Maven multi-module project; though that level of automation is not needed, I'd just like to come up with a self-contained package.

like image 559
watery Avatar asked Jan 17 '18 19:01

watery


People also ask

Can I use node JS for big projects?

Because of its non-blocking event loop mechanism, it enables developers to build highly scalable and cross-platform web applications easily. It is also a primary choice of startups. So, Node. js is the right choice for big projects.


1 Answers

These project structures are called as monorepos - A single node project repository that contains multiple packages. There are tools like Lerna. If you are using yarn as package manager, it comes with experimental feature of workspaces.

like image 86
PKV Avatar answered Oct 27 '22 20:10

PKV