Projet Svelte - express

Commandes :

Create project :
$ npx degit sveltejs/template svelte-express-app

Setup project :
$ cd svelte-express-app
$ yarn
$ yarn dev

Add Back server :
$ yarn add express --save
$ yarn add cors --save

Setup Server :

const express = require('express');
const app = express();
const port = process.env.PORT || 5000;
const cors = require('cors');
const path = require('path');
app.use(cors());
app.use(express.static('public'));
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, 'public', 'index.html'));
});
app.listen(port, () => {
console.log(`Server is up at port ${port}`);
});

Start server :

$ node server.js

Dont forget to build svelte before launch serve

Full tutorial :

tutorial

Top categories

svelte logo

Need a Svelte website built?

Hire a professional Svelte developer today.
Loading Svelte Themes