Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nodejs server esm #19

Open
wants to merge 1 commit into
base: feature/connection-v2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodejs 12.4.0
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
{
"name": "unnamed",
"name": "bazaar",
"version": "1.0.0",
"main": "index.js",
"repository": "[email protected]:pastleo/unnamed.git",
"author": "Lego Chiang <[email protected]>",
"license": "MIT",
"type": "module",
"dependencies": {
"debug": "^4.1.1",
"uuid": "^3.3.2",
"ws": "^7.0.0"
},
"scripts": {
"dev": "DEBUG=\"bazaar:*\" node --experimental-modules server/index.js"
}
}
7 changes: 5 additions & 2 deletions server/debug.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
const debug = require('debug');
import dbg from 'debug';

exports.websocket = debug('bazaar:websocket');
const debug = {
websocket: dbg('bazaar:websocket'),
}
export default debug;
10 changes: 7 additions & 3 deletions server/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
const uuid = require('uuid/v4');
const wss = require('./wss');
const debug = require('./debug');
import uuid from 'uuid';
import wss from './wss.js';
import debug from './debug.js';

// testing shared utils:
import { randomStr } from '../web_client/lib/utils.js';
console.log('testing shared utils: randomStr() =', randomStr());

/**
* @type {Map<WebSocket, string>} wsToIdMap
Expand Down
4 changes: 2 additions & 2 deletions server/wss.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const WebSocket = require('ws');
import WebSocket from 'ws';

const port = process.env.PORT || 9527;

Expand Down Expand Up @@ -26,4 +26,4 @@ const wss = new WebSocket.Server({
}
});

module.exports = wss;
export default wss;