Untitled
unknown
plain_text
a year ago
1.0 kB
7
Indexable
npm init npm i --save-exact express@ npm i --save-exact dotenv@ npm i --save-exact ejs@ npm i --save-exact nodemon@ # express ``` const express = require('express') //import express const app = express() // tạo express application const port = 3000 // init port // khai báo routes // req (request), res(response) là 2 object trong môi trường Node.js app.get('/', (req, res) => { res.send('Hello World!') }) // run server trên port đã khởi tạo trước đấy // nạp các thông tin khai báo ở trên rồi chạy (ví dụ như nạp routes) app.listen(port, () => { console.log(`Example app listening on port ${port}`) }) ``` # dotenv - tham số môi trường - định dạng: KEY=VALUE # ejs - template egine for view https://github.com/mde/ejs https://ejs.co/ https://www.npmjs.com/package/ejs # nodemon - tu dong restart mỗi khi có file thay đổi (js, mjs, coffee, litcoffee, ...) ``` //package.json "start" : "nodemon index.js" >>> npm run start ```
Editor is loading...
Leave a Comment