Segregating REST server (without framework) and Application server using Node.js

35 Views Asked by At

I am creating a Node.js application where users can write and save notes. For this I am following a tutorial. Here the author has created a folder called "users" which has it's own user-server.js and package.json without any framework. This user-server.js basically authenticates every user and if user is not present then creates the user.

The other part is the main "notes" folder which uses Express framework and deals with the actual application logic. So, if a user visits any of the application page, it will check authentication (which actually is done inside the /users folder).

Now, the author starts both the servers in two terminals. In other words, the directory structure is like this

my_application
|
|
users & notes

my_application is the main parent folder, inside which are users and notes folders. Both users and notes folder have their own package.json. The "main" property in package.json is present under users -> package.json, which means this is the main script.

My questions are:

(1) When I start both scripts... which url should I visit in browser.

http:/www.domain.com:5000

http:/www.domain.com/my_application:5000

http:/www.domain.com/users:5000

None of the above are working.

(2) The users also have routes and notes also have routes. How will they interact with each other?

I know there are are sessions and it uses passport. But, I want to get the basic understanding or logic behind it. Because I feel that it is very secure way to protect your application.

Any help or idea will be highly appreciated.

The links to the tutorial are here

Main link https://github.com/PacktPublishing/Node.js-Web-Development-Fifth-Edition/tree/master/Chapter08

users folder https://github.com/PacktPublishing/Node.js-Web-Development-Fifth-Edition/tree/master/Chapter08/users

notes folder https://github.com/PacktPublishing/Node.js-Web-Development-Fifth-Edition/tree/master/Chapter08/notes

Edited post below...

For the users part, the package.json has like this…

"main": "user-server.mjs",
  "scripts": {
    "start": "cross-env DEBUG=users:* PORT=5858 SEQUELIZE_CONNECT=sequelize-sqlite.yaml node ./user-server.mjs"
  },

For the "notes" part the package.json has like this...

"scripts": {
"start": "cross-env DEBUG=notes:*  SEQUELIZE_CONNECT=models/sequelize-sqlite.yaml NOTES_MODEL=sequelize USER_SERVICE_URL=http://localhost:5858 node ./app.mjs",
"start-server1": "cross-env DEBUG=notes:* SEQUELIZE_CONNECT=models/sequelize-sqlite.yaml NOTES_MODEL=sequelize USER_SERVICE_URL=http://localhost:5858 PORT=3000 node ./app.mjs",
"start-server2": "cross-env DEBUG=notes:* SEQUELIZE_CONNECT=models/sequelize-sqlite.yaml NOTES_MODEL=sequelize USER_SERVICE_URL=http://localhost:5858 PORT=3002 node ./app.mjs",
"dl-minty": "mkdir -p minty && npm run dl-minty-css && npm run dl-minty-min-css",
"dl-minty-css": "wget https://bootswatch.com/4/minty/bootstrap.css -O minty/bootstrap.css",
"dl-minty-min-css": "wget https://bootswatch.com/4/minty/bootstrap.min.css -O minty/bootstrap.min.css"
  },

There is no main in this package.json. Ports are the same in both.

0

There are 0 best solutions below