now using ES modules

This commit is contained in:
Karma Riuk
2025-04-28 10:12:50 +02:00
parent 630c7508a0
commit 83c53d6ed4
3 changed files with 11 additions and 10 deletions

View File

@ -1,6 +1,7 @@
{
"name": "crab-webapp",
"description": "Crab Webapp",
"type": "module",
"main": "src/server.js",
"scripts": {
"start": "node src/server.js",

View File

@ -1,14 +1,14 @@
const express = require('express');
const router = express.Router();
import { Router } from 'express';
const router = Router();
// Routes
router.get('/', (req, res) => {
res.json({ message: 'Welcome to the Express backend!' });
res.json({ message: 'Welcome to the Express backend!' });
});
// Example route
router.get('/api/hello', (req, res) => {
res.json({ message: 'Hello from the backend!' });
res.json({ message: 'Hello from the backend!' });
});
module.exports = router;
export default router;

View File

@ -1,15 +1,15 @@
const express = require('express');
const cors = require('cors');
import express, { json } from 'express';
import cors from 'cors';
require('dotenv').config();
const routes = require('./routes');
import routes from './routes';
const app = express();
const port = process.env.PORT || 3000;
// Middleware
app.use(cors());
app.use(express.json());
app.use(json());
// Use routes
app.use('/', routes);
@ -17,4 +17,4 @@ app.use('/', routes);
// Start server
app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});
});