Skip to content

Instantly share code, notes, and snippets.

@dkotama
Created July 15, 2020 09:12
Show Gist options
  • Save dkotama/bfa9f20bae65c9df81ca28a0bf67b6cf to your computer and use it in GitHub Desktop.
Save dkotama/bfa9f20bae65c9df81ca28a0bf67b6cf to your computer and use it in GitHub Desktop.
server.js buat kak ferdy
const express = require('express');
const app = express();
const cors = require('cors');
const http = require('http').createServer(app);
const path = require('path');
// setup cors
app.use(cors());
// serve static files
app.use('/public', express.static(path.join(__dirname, 'public')));
// start server
http.listen(3000, function() {
console.log('Server started!');
});
@dkotama
Copy link
Author

dkotama commented Jul 15, 2020

Setelah buat server.js ini run di command line

npm install -d nodemon

tunggu , lalu install

npm install --save cors express

kira kira package json akan terlihat seperti ini

{
  "name": "multiplayer-card",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "nodemon server.js",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "cors": "^2.8.5",
    "express": "^4.17.1",
  },
  "devDependencies": {
    "nodemon": "^2.0.2"
  }
}

letakkan semua file html & js nya di folder /public jadi strukturnya

/root-path
|-/public
|  |- index.html
|  |-/js
|  |-/assets
|-server.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment