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

200
Visualizações
I still not understanding how to use Node Js

I have over 20 years experience in PHP programming, started and tried to learn Node Js in almost half year, but still not yet understanding how to use it...

I saw many samples on learning Node Js with ExpressJs, which is a framework can be served a website/app on a port (e.g. 3000). But, would there a way working without ExpressJs? I tried to upload that files directly to server, but it turned out loading index.html, not index.js

I also tried to call it as Module in my existing html file, but while calling 'import' it fire an error

Relative module specifiers must start with “./”, “../” or “/”.

Since I don't want to separate main site (:80) and node js (:3000) to different sites, how can I get it work together? Do I need to rewrite whole the existing website (in PHP) to node js and map :3000 to :80 for that?

Is it a general way most node js app running?

Thanks so much.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I'll summarise PHP first as a point of reference since you are familiar with it already.

To run a server-side PHP program you typically pick an HTTP server, such as Apache HTTP. A default configuration of this will map URLs onto a path on the file system. For example, asking the server for /foo.html will load the file stored at /var/www/html/foo.html.

You configure the server so if the file ends in .php then instead of sending the file directly to the browser, it is executed with PHP and the output is sent to the browser.

If you want two URLs to trigger PHP code, then you put a .php file at both.

That's a simple approach to running PHP. More complex options are available (with pros and cons).

There are lots of hosting plans designed to support PHP programs running this way. So many that if you buy a cheap hosting plan then you can often just assume it will support this approach.


Node.js is a program for executing JavaScript.

A typical approach to using it for server-side programming involves writing a JavaScript program that creates a webserver that you use instead of something like Apache HTTPD.

Normally you would write that webserver using something like Express.js (which takes all the pain out of it).

This JavaScript program is responsible for handling the URLs (since you aren't using Apache, it won't do it for you). This is why Express.js is popular: It makes mapping URLs onto functions easy.

To set up Node.js on your hosting plan, you need either:

  • a hosting plan which explicitly supports it or
  • a hosting plan which gives you admin access to configure everything yourself

You generally do not find hosting plans that are "drop some JS files onto a server and it will just work".

Hosting services like Heroku, designed for running Node.js projects, will have straight forward setup instructions.

If you are doing everything yourself, then a typical set up process would look something like:

  1. Upload your code to the server
  2. Install the dependencies with npm i
  3. Run it using a tool like pm2 that will restart it automatically if it falls over or the server reboots

Often you will use something like Docker to bundle everything up in a package that you can just deploy to a service that supports Docker containers.

You can also take a significantly different approach and use something like a AWS lambda function.


Since I don't want to separate main site (:80) and node js (:3000) to different sites, how can I get it work together?

You can run a Node.js server on one port, and Apache (or another HTTPD on another) and proxy requests from Apache to Node.

Even if you aren't using PHP, this is a useful approach to have a more efficient service for handling static files (e.g. images and css) and lets you add caching features between the server-side code and the client.

about 4 years ago · Juan Pablo Isaza 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