LoginSignup
0
0

More than 5 years have passed since last update.

[WIP] Express で Shift_JIS な文字列を UNICODE にする

Posted at

そのうち完全に理解したら書き足します。たぶん。

やりたいこと

  • Node.js v8 ~
  • Express
  • POST でリクエストボディに Shift_JIS な文字列が詰まってる
  • 文字列を JavaScript で処理したいので UNICODE にしたい

やりかた

app.js
const express = require('express')
const bodyParser = require('body-parser')
const encoding = require('encoding-japanese')

const PORT = process.env.PORT || 3000

const app = express()

app.use(bodyParser.urlencoded({ extended: true }))

app.post('/', (req, res) => {
  const decoded = encoding.urlDecode(req.body.message)
  const buffer = Buffer.from(decoded)
  const str = encoding.convert(buffer, {
    to: 'UNICODE',
    from: 'SJIS',
    type: 'string'
  })
})

app.listen(PORT, () => {
  console.log(`Listening on port ${PORT}`)
})

です。

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0