Skip to content

QueenieCplusplus/Backend_Script_Nodejs_Server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Backend_Script_Nodejs_Server

使用 npm 之前,都請先至官網下載 Nodejs !

在終端機 cd 此 file 的資料夾後,下指令 node filename 即可。

// 2021, 2/21 sun

const http = require('http');

const hostname = 'localhost';
const port = 3000;

const server = http.createServer((req, res) => {

    res.statusCode = 200;
    res.setHeader = ('content-Type', 'text/html');
    res.end(`<h1> This is my nodejs server </h1>`);

})

server.listen(port, hostname, () =>{
    console.log(`my server is listening on http://${hostname}:${port}.`)
})

ref:

https://medium.com/pierceshih/筆記-如何使用-node-js-建立一個本機伺服器-30b8d91c3ec1 (無 express)

https://expressjs.com/zh-tw/starter/installing.html (有 express)

https://expressjs.com/zh-tw/starter/generator.html (Express 框架)