javascript Express 1 - Découverted'express
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript Express 1 - Découverted'express相关的知识,希望对你有一定的参考价值。
const express = require('express');
const app = express();
const port = 3000;
const movies = [
{id : 1, name : 'Death Proof'},
{id : 2, name : 'Goodfellas'},
{id : 3, name : 'Cape Fear'}
]
app.get('/', (request, response) => {
response.send('Bienvenue sur Express');
})
app.get('/api/movies', (request, response) => {
response.send('Récupération de tous les films')
});
app.get('/api/movies/:id', (request, response) => {
const movie = movies.filter((thisid) => thisid.id === parseInt(request.params.id))
response.json(movie)
});
app.get('/api/employee', (request, response) => {
let name = request.query.name
if(name) {
response.status(404).send(`impossible de récupérer l'employé ${name}`);
} else {
console.log('You are redirected')
response.status(304).send('redirected');
}
});
app.listen(port, (err) => {
if (err) {
throw new Error('Something bad happened...');
}
console.log(`Server is listening on ${port}`);
});
以上是关于javascript Express 1 - Découverted'express的主要内容,如果未能解决你的问题,请参考以下文章
使用 Express 时未加载 Javascript (Angular)
javascript Express - 简单的路由演示
javascript EXPRESS插入
javascript express3.js
javascript Express 2 - MySQL和Postman
javascript 如何在Express中提供图像?