N
N
newaitix2020-05-02 20:44:49
Node.js
newaitix, 2020-05-02 20:44:49

How to use the server language in a document?

const localConfig = require('./localConfig.js');
const express = require("express");
const http = require('http');
const https = require('https');
const fs = require('fs');
const app = express();
const httpServer = http.createServer(app);
const httpsServer = https.createServer(app);






httpServer.listen(8080,function(){
  console.log('HTTP Server running on port 8080');
});
httpsServer.listen(443,function(){
  console.log('HTTPS Server running on port 443');
});

app.get('/',function(req,res){
  res.status(200);
  res.setHeader('Content-Type','text/html');
  res.sendfile('index.php');
  //res.send('Hello');
});
app.post('/',function(req,res){
  res.status(200);
  res.setHeader('Content-Type','text/html');
  res.send('Hello');
});






app.get('*',function(req,res){
  res.status(404);
  res.setHeader('Content-Type','text/plain');
  res.send('Not found');
});
app.post('*',function(req,res){
  res.status(404);
  res.setHeader('Content-Type','text/plain');
  res.send('Not found');
});

If we take apache + php or nginx + php, then there I could decide to give the content or not inside the file itself.
For example, the index.php file might contain the following code:
Какой то текст.
<?
if(isset($_GET['test'])){
echo 'Строка из php';
}
?>
Какой то текст.

In this case, "Some text." will be displayed on the page as is, and "String from php" will be displayed if test.
And I could make a decision to display "String from php" or not to display it inside the file itself. So if the get parameter test was absent in the request, then "String from php" will generally be absent in the response from the server.

What about nodejs? How can I write in it a condition that will be executed on the server and the content will either be displayed or not?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question