Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

172
Visualizações
Is it good practice to run a backend and a frontend server with express in NodeJS?

I am currently working on a simple NodeJS/AngularJS application and my current project looks like this:

/frontend/index.html <-- AngularJS home page
/frontend/js/app.js  <-- AngularJS app.js
/backend/package.json<-- NodeJS package.json
/backend/index.js    <-- NodeJS script

and I am only serving the backend API with my NodeJS express server while I open the frontend part directly (file://.../frontend/index.html) in my browser.

Is it good practice to serve both the "Backend API" and the frontend with NodeJS (e.g. with two express instances running) and how would I organize the code?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

while I open the frontend part directly (file://.../frontend/index.html) in my browser.

That is something you can only do on your own local computer. You cannot do that for a regular web server that other people can use. So, that is NOT considered a viable practice for a regular web server designed for other people on the internet to use.

With one line of code using express.static() middleware you can have your existing node.js server also serve all your static HTML files. You do not need a separate process for serving the HTML files. At super large scale, you might use something like an NGINX proxy to serve your static HTML files, but I don't see any reason for you to be going that direction now. At this point, just have your existing node.js server use express.static() to serve your static files and stop using any file:// references.

Is it good practice to serve both the "Backend API" and the frontend with NodeJS (e.g. with two express instances running) and how would I organize the code?

No. You've shown no reason why you would need two node.js instances. Just use the one instance to serve both the API and the static HTML files.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda